Commit 446144da authored by Joachim Pouderoux's avatar Joachim Pouderoux Committed by Kitware Robot
Browse files

Merge topic 'AddSupportForMoleculeInProgrammableFilter'

e617390c

 Add support for vtkMolecule I/O in Programmable Filter & Source.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Acked-by: Nicolas Vuaille's avatarNicolas Vuaille <nicolas.vuaille@kitware.com>
Merge-request: !3601
parents ad06fd60 e617390c
......@@ -19,6 +19,7 @@
#include "vtkGraph.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMolecule.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
......@@ -94,17 +95,24 @@ vtkRectilinearGrid *vtkPassInputTypeAlgorithm::GetRectilinearGridOutput()
}
//----------------------------------------------------------------------------
// Get the output as vtkTable.
vtkTable *vtkPassInputTypeAlgorithm::GetTableOutput()
// Get the output as vtkGraph.
vtkGraph *vtkPassInputTypeAlgorithm::GetGraphOutput()
{
return vtkTable::SafeDownCast(this->GetOutput());
return vtkGraph::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
// Get the output as vtkGraph.
vtkGraph *vtkPassInputTypeAlgorithm::GetGraphOutput()
// Get the output as vtkMolecule.
vtkMolecule *vtkPassInputTypeAlgorithm::GetMoleculeOutput()
{
return vtkGraph::SafeDownCast(this->GetOutput());
return vtkMolecule::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
// Get the output as vtkTable.
vtkTable *vtkPassInputTypeAlgorithm::GetTableOutput()
{
return vtkTable::SafeDownCast(this->GetOutput());
}
//----------------------------------------------------------------------------
......
......@@ -40,12 +40,13 @@
class vtkDataObject;
class vtkGraph;
class vtkImageData;
class vtkMolecule;
class vtkPolyData;
class vtkStructuredPoints;
class vtkStructuredGrid;
class vtkUnstructuredGrid;
class vtkRectilinearGrid;
class vtkStructuredGrid;
class vtkStructuredPoints;
class vtkTable;
class vtkUnstructuredGrid;
class VTKCOMMONEXECUTIONMODEL_EXPORT vtkPassInputTypeAlgorithm : public vtkAlgorithm
{
......@@ -62,45 +63,20 @@ public:
vtkDataObject* GetOutput(int);
//@}
//@{
/**
* Get the output as vtkPolyData.
* Get the output as a concrete type.
*/
vtkPolyData *GetPolyDataOutput();
/**
* Get the output as vtkStructuredPoints.
*/
vtkStructuredPoints *GetStructuredPointsOutput();
/**
* Get the output as vtkStructuredPoints.
*/
vtkImageData *GetImageDataOutput();
/**
* Get the output as vtkStructuredGrid.
*/
vtkStructuredGrid *GetStructuredGridOutput();
/**
* Get the output as vtkUnstructuredGrid.
*/
vtkUnstructuredGrid *GetUnstructuredGridOutput();
/**
* Get the output as vtkRectilinearGrid.
*/
vtkRectilinearGrid *GetRectilinearGridOutput();
/**
* Get the output as vtkTable.
*/
vtkTable *GetTableOutput();
/**
* Get the output as vtkGraph.
*/
vtkGraph *GetGraphOutput();
vtkMolecule* GetMoleculeOutput();
vtkTable *GetTableOutput();
//@}
/**
* Get the input data object. This method is not recommended for use, but
......
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestProgrammableFilter.cxx,NO_VALID
TestProgrammableGlyph.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestProgrammableFilter.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.
=========================================================================*/
#include <vtkDirectedGraph.h>
#include <vtkMolecule.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkProgrammableFilter.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredPoints.h>
#include <vtkTable.h>
#include <vtkUnstructuredGrid.h>
#define EXECUTE_METHOD(_type) \
void _type##ExecuteMethod(void *args) \
{ \
vtkProgrammableFilter* self = reinterpret_cast<vtkProgrammableFilter*>(args); \
vtk ## _type* input = self->Get ## _type ## Input(); \
vtk ## _type* output = self->Get ## _type ## Output(); \
if (!input) \
{ \
std::cerr << "Input type is not of type " #_type "!" << std::endl; \
exit(EXIT_FAILURE); \
} \
if (!output) \
{ \
std::cerr << "Output type is not of type " #_type "!" << std::endl; \
exit(EXIT_FAILURE); \
} \
}
EXECUTE_METHOD(PolyData);
EXECUTE_METHOD(StructuredPoints);
EXECUTE_METHOD(StructuredGrid);
EXECUTE_METHOD(UnstructuredGrid);
EXECUTE_METHOD(RectilinearGrid);
EXECUTE_METHOD(Graph);
EXECUTE_METHOD(Molecule);
EXECUTE_METHOD(Table);
#define TEST_PROGRAMMABLE_FILTER_B(_intype, _type) \
{ \
vtkNew<vtk ## _intype> inData; \
vtkNew<vtkProgrammableFilter> ps; \
ps->SetInputData(inData.Get()); \
ps->SetExecuteMethod(& _type ## ExecuteMethod, ps.Get()); \
ps->Update(); \
vtk ## _type* output = ps->Get ## _type ## Output(); \
if (!output) \
{ \
std::cerr << "Filter output type is not of type " #_type "!" << std::endl; \
return EXIT_FAILURE; \
} \
}
#define TEST_PROGRAMMABLE_FILTER_A(_type)\
TEST_PROGRAMMABLE_FILTER_B(_type, _type)
int TestProgrammableFilter(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
TEST_PROGRAMMABLE_FILTER_A(PolyData);
TEST_PROGRAMMABLE_FILTER_A(StructuredPoints);
TEST_PROGRAMMABLE_FILTER_A(StructuredGrid);
TEST_PROGRAMMABLE_FILTER_A(UnstructuredGrid);
TEST_PROGRAMMABLE_FILTER_A(RectilinearGrid);
TEST_PROGRAMMABLE_FILTER_B(DirectedGraph, Graph);
TEST_PROGRAMMABLE_FILTER_A(Molecule);
TEST_PROGRAMMABLE_FILTER_A(Table);
return EXIT_SUCCESS;
}
......@@ -17,6 +17,7 @@
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataSet.h"
#include "vtkGraph.h"
#include "vtkMolecule.h"
#include "vtkPolyData.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
......@@ -54,43 +55,49 @@ vtkProgrammableFilter::~vtkProgrammableFilter()
// the correct type of the input data.
vtkPolyData *vtkProgrammableFilter::GetPolyDataInput()
{
return (vtkPolyData *)this->GetInput();
return static_cast<vtkPolyData*>(this->GetInput());
}
// Get the input as a concrete type.
vtkStructuredPoints *vtkProgrammableFilter::GetStructuredPointsInput()
{
return (vtkStructuredPoints *)this->GetInput();
return static_cast<vtkStructuredPoints*>(this->GetInput());
}
// Get the input as a concrete type.
vtkStructuredGrid *vtkProgrammableFilter::GetStructuredGridInput()
{
return (vtkStructuredGrid *)this->GetInput();
return static_cast<vtkStructuredGrid*>(this->GetInput());
}
// Get the input as a concrete type.
vtkUnstructuredGrid *vtkProgrammableFilter::GetUnstructuredGridInput()
{
return (vtkUnstructuredGrid *)this->GetInput();
return static_cast<vtkUnstructuredGrid*>(this->GetInput());
}
// Get the input as a concrete type.
vtkRectilinearGrid *vtkProgrammableFilter::GetRectilinearGridInput()
{
return (vtkRectilinearGrid *)this->GetInput();
return static_cast<vtkRectilinearGrid*>(this->GetInput());
}
// Get the input as a concrete type.
vtkGraph *vtkProgrammableFilter::GetGraphInput()
{
return (vtkGraph *)this->GetInput();
return static_cast<vtkGraph*>(this->GetInput());
}
// Get the input as a concrete type.
vtkMolecule *vtkProgrammableFilter::GetMoleculeInput()
{
return static_cast<vtkMolecule*>(this->GetInput());
}
// Get the input as a concrete type.
vtkTable *vtkProgrammableFilter::GetTableInput()
{
return (vtkTable *)this->GetInput();
return static_cast<vtkTable*>(this->GetInput());
}
// Specify the function to use to operate on the point attribute data. Note
......@@ -176,6 +183,24 @@ int vtkProgrammableFilter::RequestData(
}
}
}
if (vtkMolecule::SafeDownCast(objInput))
{
vtkMolecule *molInput = vtkMolecule::SafeDownCast(objInput);
vtkMolecule *molOutput = vtkMolecule::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
// First, copy the input to the output as a starting point
if (molInput && molOutput && molInput->GetDataObjectType() == molOutput->GetDataObjectType())
{
if (this->CopyArrays)
{
molOutput->ShallowCopy(molInput);
}
else
{
molOutput->CopyStructure(molInput);
}
}
}
if (vtkTable::SafeDownCast(objInput))
{
vtkTable *tableInput = vtkTable::SafeDownCast(objInput);
......@@ -245,6 +270,7 @@ int vtkProgrammableFilter::FillInputPortInformation(int vtkNotUsed(port), vtkInf
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(), "vtkMolecule");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable");
return 1;
}
......
......@@ -43,8 +43,6 @@
#include "vtkFiltersProgrammableModule.h" // For export macro
#include "vtkPassInputTypeAlgorithm.h"
class vtkGraph;
class vtkTable;
class VTKFILTERSPROGRAMMABLE_EXPORT vtkProgrammableFilter : public vtkPassInputTypeAlgorithm
{
......@@ -75,6 +73,7 @@ public:
*/
void SetExecuteMethodArgDelete(void (*f)(void *));
//@{
/**
* Get the input as a concrete type. This method is typically used by the
* writer of the filter function to get the input as a particular type (i.e.,
......@@ -82,37 +81,14 @@ public:
* the correct type of the input data.
*/
vtkPolyData *GetPolyDataInput();
/**
* Get the input as a concrete type.
*/
vtkStructuredPoints *GetStructuredPointsInput();
/**
* Get the input as a concrete type.
*/
vtkStructuredGrid *GetStructuredGridInput();
/**
* Get the input as a concrete type.
*/
vtkUnstructuredGrid *GetUnstructuredGridInput();
/**
* Get the input as a concrete type.
*/
vtkRectilinearGrid *GetRectilinearGridInput();
/**
* Get the input as a concrete type.
*/
vtkGraph *GetGraphInput();
/**
* Get the input as a concrete type.
*/
vtkMolecule *GetMoleculeInput();
vtkTable *GetTableInput();
//@}
//@{
/**
......
......@@ -18,6 +18,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestPlatonicSolidSource.cxx,NO_VALID
TestPointSource.cxx,NO_VALID
TestPolyLineSource.cxx,NO_VALID
TestProgrammableSource.cxx,NO_VALID
TestRectangularButtonSource.cxx,NO_VALID
TestRegularPolygonSource.cxx,NO_VALID
TestSphereSource.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestProgrammableSource.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.
=========================================================================*/
#include <vtkMolecule.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkProgrammableSource.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredPoints.h>
#include <vtkTable.h>
#include <vtkUnstructuredGrid.h>
#define EXECUTE_METHOD(_type) \
void _type##ExecuteMethod(void *args) \
{ \
vtkProgrammableSource* self = reinterpret_cast<vtkProgrammableSource*>(args); \
vtk ## _type* output = self->Get ## _type ## Output(); \
if (!output) \
{ \
std::cerr << "Output type is not of type " #_type "!" << std::endl; \
exit(EXIT_FAILURE); \
} \
}
EXECUTE_METHOD(PolyData);
EXECUTE_METHOD(StructuredPoints);
EXECUTE_METHOD(StructuredGrid);
EXECUTE_METHOD(UnstructuredGrid);
EXECUTE_METHOD(RectilinearGrid);
EXECUTE_METHOD(Molecule);
EXECUTE_METHOD(Table);
#define TEST_PROGRAMMABLE_SOURCE(_type) \
{ \
vtkNew<vtkProgrammableSource> ps; \
ps->SetExecuteMethod(& _type ## ExecuteMethod, ps.Get()); \
ps->Update(); \
vtk ## _type* output = ps->Get ## _type ## Output(); \
if (!output) \
{ \
std::cerr << "Source output type is not of type " #_type "!" << std::endl; \
return EXIT_FAILURE; \
} \
}
int TestProgrammableSource(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
TEST_PROGRAMMABLE_SOURCE(PolyData);
TEST_PROGRAMMABLE_SOURCE(StructuredPoints);
TEST_PROGRAMMABLE_SOURCE(StructuredGrid);
TEST_PROGRAMMABLE_SOURCE(UnstructuredGrid);
TEST_PROGRAMMABLE_SOURCE(RectilinearGrid);
TEST_PROGRAMMABLE_SOURCE(Molecule);
TEST_PROGRAMMABLE_SOURCE(Table);
return EXIT_SUCCESS;
}
......@@ -13,16 +13,20 @@
=========================================================================*/
#include "vtkProgrammableSource.h"
#include "vtkPolyData.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkRectilinearGrid.h"
#include "vtkCommand.h"
#include "vtkExecutive.h"
#include "vtkGraph.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMolecule.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"
#include "vtkPolyData.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkTable.h"
#include "vtkUnstructuredGrid.h"
vtkStandardNewMacro(vtkProgrammableSource);
......@@ -35,27 +39,39 @@ vtkProgrammableSource::vtkProgrammableSource()
this->RequestInformationMethod = nullptr;
this->SetNumberOfInputPorts(0);
this->SetNumberOfOutputPorts(5);
this->SetNumberOfOutputPorts(8);
vtkDataSet *output;
vtkDataObject *output;
output = vtkPolyData::New();
this->GetExecutive()->SetOutputData(0,output);
this->GetExecutive()->SetOutputData(0, output);
output->Delete();
output = vtkStructuredPoints::New();
this->GetExecutive()->SetOutputData(1,output);
this->GetExecutive()->SetOutputData(1, output);
output->Delete();
output = vtkStructuredGrid::New();
this->GetExecutive()->SetOutputData(2,output);
this->GetExecutive()->SetOutputData(2, output);
output->Delete();
output = vtkUnstructuredGrid::New();
this->GetExecutive()->SetOutputData(3,output);
this->GetExecutive()->SetOutputData(3, output);
output->Delete();
output = vtkRectilinearGrid::New();
this->GetExecutive()->SetOutputData(4,output);
this->GetExecutive()->SetOutputData(4, output);
output->Delete();
output = vtkGraph::New();
this->GetExecutive()->SetOutputData(5, output);
output->Delete();
output = vtkMolecule::New();
this->GetExecutive()->SetOutputData(6, output);
output->Delete();
output = vtkTable::New();
this->GetExecutive()->SetOutputData(7, output);
output->Delete();
this->RequestedDataType = VTK_POLY_DATA;
......@@ -109,14 +125,13 @@ void vtkProgrammableSource::SetRequestInformationMethod(
}
}
// Get the output as a concrete type. This method is typically used by the
// writer of the source function to get the output as a particular type (i.e.,
// it essentially does type casting). It is the users responsibility to know
// the correct type of the output data.
vtkPolyData *vtkProgrammableSource::GetPolyDataOutput()
{
if (this->GetNumberOfOutputPorts() < 5)
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
......@@ -129,7 +144,7 @@ vtkPolyData *vtkProgrammableSource::GetPolyDataOutput()
// Get the output as a concrete type.
vtkStructuredPoints *vtkProgrammableSource::GetStructuredPointsOutput()
{
if (this->GetNumberOfOutputPorts() < 5)
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
......@@ -155,7 +170,7 @@ vtkStructuredGrid *vtkProgrammableSource::GetStructuredGridOutput()
// Get the output as a concrete type.
vtkUnstructuredGrid *vtkProgrammableSource::GetUnstructuredGridOutput()
{
if (this->GetNumberOfOutputPorts() < 5)
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
......@@ -168,7 +183,7 @@ vtkUnstructuredGrid *vtkProgrammableSource::GetUnstructuredGridOutput()
// Get the output as a concrete type.
vtkRectilinearGrid *vtkProgrammableSource::GetRectilinearGridOutput()
{
if (this->GetNumberOfOutputPorts() < 5)
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
......@@ -178,12 +193,51 @@ vtkRectilinearGrid *vtkProgrammableSource::GetRectilinearGridOutput()
this->GetExecutive()->GetOutputData(4));
}
// Get the output as a concrete type.
vtkGraph *vtkProgrammableSource::GetGraphOutput()
{
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
this->RequestedDataType = VTK_GRAPH;
return vtkGraph::SafeDownCast(
this->GetExecutive()->GetOutputData(5));
}
// Get the output as a concrete type.
vtkMolecule *vtkProgrammableSource::GetMoleculeOutput()
{
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
this->RequestedDataType = VTK_MOLECULE;
return vtkMolecule::SafeDownCast(
this->GetExecutive()->GetOutputData(6));
}
// Get the output as a concrete type.
vtkTable *vtkProgrammableSource::GetTableOutput()
{
if (this->GetNumberOfOutputPorts() < 8)
{
return nullptr;
}
this->RequestedDataType = VTK_TABLE;
return vtkTable::SafeDownCast(
this->GetExecutive()->GetOutputData(7));
}
int vtkProgrammableSource::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *vtkNotUsed(outputVector))
{
vtkDebugMacro(<<"Executing programmable filter");
vtkDebugMacro(<<"Executing programmable source");
// Now invoke the procedure, if specified.
if ( this->ExecuteMethod != nullptr )
......@@ -200,7 +254,7 @@ int vtkProgrammableSource::RequestDataObject(
vtkInformationVector *outputVector)
{
vtkInformation *outInfo;
vtkDataSet *output = nullptr;
vtkDataObject *output = nullptr;
switch (this->RequestedDataType)
{
case VTK_POLY_DATA:
......@@ -310,7 +364,73 @@ int vtkProgrammableSource::RequestDataObject(
return 1;
}
}
this->GetExecutive()->SetOutputData(3, output);
this->GetExecutive()->SetOutputData(4, output);