[vtk-developers] [VTK 0012985]: vtkDataObjectToTable don't transfere points
Mantis Bug Tracker
mantis at public.kitware.com
Fri Mar 9 10:37:53 EST 2012
The following issue has been SUBMITTED.
======================================================================
http://vtk.org/Bug/view.php?id=12985
======================================================================
Reported By: Dominic Plourde
Assigned To:
======================================================================
Project: VTK
Issue ID: 12985
Category: (No Category)
Reproducibility: have not tried
Severity: minor
Priority: normal
Status: backlog
Project: TBD
Type: incorrect functionality
Resolution: open
Fixed in Version:
======================================================================
Date Submitted: 2012-03-09 10:37 EST
Last Modified: 2012-03-09 10:37 EST
======================================================================
Summary: vtkDataObjectToTable don't transfere points
Description:
I made a patch for create 3 news columns(X, Y, Z) in the vtkTable output when
the option IsTransferPoints is set to On.
Diff:
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataObjectToTable.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
// .NAME vtkDataObjectToTable - extract field data as a table
//
// .SECTION Description
// This filter is used to extract either the field, cell or point data of
// any data object as a table.
#ifndef __vtkDataObjectToTable_h
#define __vtkDataObjectToTable_h
#include "vtkTableAlgorithm.h"
class VTK_INFOVIS_EXPORT vtkDataObjectToTable : public vtkTableAlgorithm
{
public:
static vtkDataObjectToTable* New();
vtkTypeMacro(vtkDataObjectToTable,vtkTableAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
//BTX
enum
{
FIELD_DATA = 0,
POINT_DATA = 1,
CELL_DATA = 2,
VERTEX_DATA = 3,
EDGE_DATA = 4
};
//ETX
// Description:
// The field type to copy into the output table.
// Should be one of FIELD_DATA, POINT_DATA, CELL_DATA, VERTEX_DATA, EDGE_DATA.
vtkGetMacro(FieldType, int);
vtkSetClampMacro(FieldType, int, 0, 4);
+ // Description:
+ // Turn on/off the transfere of points to the output.
+ vtkGetMacro(IsTransferPoints, bool);
+ vtkSetMacro(IsTransferPoints, bool);
+ vtkBooleanMacro(IsTransferPoints, bool);
protected:
vtkDataObjectToTable();
~vtkDataObjectToTable();
int FillInputPortInformation(int port, vtkInformation* info);
+ void AddPointsColumn(vtkTable *output, vtkDataObject *input);
int RequestData(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
int FieldType;
+ bool IsTransferPoints;
private:
vtkDataObjectToTable(const vtkDataObjectToTable&); // Not implemented
void operator=(const vtkDataObjectToTable&); // Not implemented
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataObjectToTable.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
#include "vtkDataObjectToTable.h"
#include "vtkCellData.h"
#include "vtkDataObject.h"
#include "vtkDataSet.h"
#include "vtkDataSetAttributes.h"
#include "vtkGraph.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
+ #include "vtkPointSet.h"
#include "vtkTable.h"
+ #include "vtkPoints.h"
+ #include "vtkDoubleArray.h"
vtkStandardNewMacro(vtkDataObjectToTable);
//---------------------------------------------------------------------------
vtkDataObjectToTable::vtkDataObjectToTable()
{
this->FieldType = POINT_DATA;
}
//---------------------------------------------------------------------------
vtkDataObjectToTable::~vtkDataObjectToTable()
{
}
//---------------------------------------------------------------------------
int vtkDataObjectToTable::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkGraph");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable");
return 1;
}
//---------------------------------------------------------------------------
int vtkDataObjectToTable::RequestData(
vtkInformation*,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// Get input data
vtkInformation* inputInfo = inputVector[0]->GetInformationObject(0);
vtkDataObject* input = inputInfo->Get(vtkDataObject::DATA_OBJECT());
// Get output table
vtkInformation* outputInfo = outputVector->GetInformationObject(0);
vtkTable* output = vtkTable::SafeDownCast(
outputInfo->Get(vtkDataObject::DATA_OBJECT()));
// If the input is a table, just copy it into the output.
if (vtkTable::SafeDownCast(input))
{
output->ShallowCopy(input);
return 1;
}
vtkDataSetAttributes* data = vtkDataSetAttributes::New();
switch(this->FieldType)
{
case FIELD_DATA:
if(input->GetFieldData())
{
data->ShallowCopy(input->GetFieldData());
}
break;
case POINT_DATA:
if(vtkDataSet* const dataset = vtkDataSet::SafeDownCast(input))
{
if(dataset->GetPointData())
{
data->ShallowCopy(dataset->GetPointData());
}
}
break;
case CELL_DATA:
if(vtkDataSet* const dataset = vtkDataSet::SafeDownCast(input))
{
if(dataset->GetCellData())
{
data->ShallowCopy(dataset->GetCellData());
}
}
break;
case VERTEX_DATA:
if(vtkGraph* const graph = vtkGraph::SafeDownCast(input))
{
if(graph->GetVertexData())
{
data->ShallowCopy(graph->GetVertexData());
}
}
break;
case EDGE_DATA:
if(vtkGraph* const graph = vtkGraph::SafeDownCast(input))
{
if(graph->GetEdgeData())
{
data->ShallowCopy(graph->GetEdgeData());
}
}
break;
}
output->SetRowData(data);
+ if(GetIsTransferPoints())
+ AddPointsColumn(output, input);
data->Delete();
return 1;
}
+
+//---------------------------------------------------------------------------
+void vtkDataObjectToTable::AddPointsColumn(vtkTable* output, vtkDataObject*
input)
+{
+ if(vtkPointSet* const pointsSet = vtkPointSet::SafeDownCast(input))
+ {
+ vtkPoints* points = pointsSet->GetPoints();
+
+ if(points->GetNumberOfPoints() > 0)
+ {
+ vtkDoubleArray* xArray = vtkDoubleArray::New();
+ vtkDoubleArray* yArray = vtkDoubleArray::New();
+ vtkDoubleArray* zArray = vtkDoubleArray::New();
+
+ xArray->SetName("X");
+ yArray->SetName("Y");
+ zArray->SetName("Z");
+
+ for(int i=0; i<points->GetNumberOfPoints(); ++i)
+ {
+ double* currentPoint = points->GetPoint(i);
+ xArray->InsertNextValue(currentPoint[0]);
+ yArray->InsertNextValue(currentPoint[1]);
+ zArray->InsertNextValue(currentPoint[2]);
+ }
+ output->AddColumn(xArray);
+ output->AddColumn(yArray);
+ output->AddColumn(zArray);
+ }
+ }
+}
//---------------------------------------------------------------------------
void vtkDataObjectToTable::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "FieldType: " << this->FieldType << endl;
}
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2012-03-09 10:37 Dominic PlourdeNew Issue
2012-03-09 10:37 Dominic PlourdeFile Added: vtkDataObjectToTable.zip
======================================================================
More information about the vtk-developers
mailing list