VTK/Tutorials/MemberVariables: Difference between revisions
Daviddoria (talk | contribs) |
No edit summary |
||
(3 intermediate revisions by one other user not shown) | |||
Line 10: | Line 10: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
#include | #include <vtkDenseArray.h> | ||
</source> | </source> | ||
Line 98: | Line 98: | ||
==CMakeLists.txt== | ==CMakeLists.txt== | ||
<source lang=" | <source lang="cmake"> | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
project(NonSmartPointerMember) | |||
find_package(VTK REQUIRED) | |||
include(${VTK_USE_FILE}) | |||
add_executable(NonSmartPointerMember NonSmartPointerMember.cxx MyClass.cxx) | |||
if(VTK_LIBRARIES) | |||
target_link_libraries(NonSmartPointerMember ${VTK_LIBRARIES}) | |||
else() | |||
target_link_libraries(NonSmartPointerMember vtkHybrid) | |||
endif() | |||
</source> | </source> |
Latest revision as of 18:49, 6 May 2014
Here are some common errors when trying to use a templated VTK class as a member variable. We will use vtkDenseArray as an example.
error: 'vtkDenseArray' is not a template
You have forward declared the class in your header: <source lang="cpp"> class vtkDenseArray; </source>
but forgotten to actually include the header in your implementation file:
<source lang="cpp">
- include <vtkDenseArray.h>
</source>
== error: 'vtkDenseArray' is not a template error: template argument required for 'class vtkDenseArray' ==
MyClass.h
<source lang="cpp">
- ifndef __vtkMyClass_h
- define __vtkMyClass_h
- include "vtkPolyDataAlgorithm.h" //superclass
class vtkDenseArray;
class vtkMyClass : public vtkPolyDataAlgorithm {
public:
static vtkMyClass *New(); vtkTypeRevisionMacro(vtkMyClass,vtkObject); void PrintSelf(ostream &os, vtkIndent indent);
protected:
vtkMyClass(); ~vtkMyClass(); int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); //the function that makes this class work with the vtk pipeline
private:
vtkDenseArray<double>* OutputGrid;
};
- endif
</source>
MyClass.cxx
<source lang="cpp">
- include "vtkObjectFactory.h" //for new() macro
- include "vtkInformation.h"
- include "vtkInformationVector.h"
- include "vtkDenseArray.h"
- include "MyClass.h"
vtkCxxRevisionMacro(vtkMyClass, "$Revision: 1.1 $"); vtkStandardNewMacro(vtkMyClass);
vtkMyClass::vtkMyClass() {
this->OutputGrid = vtkDenseArray<double>::New();
}
vtkMyClass::~vtkMyClass() {
this->OutputGrid->Delete();
}
int vtkMyClass::RequestData(vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
return 1;
}
void vtkMyClass::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
} </source>
NonSmartPointerMember.cxx
<source lang="cpp">
- include <vtkSmartPointer.h>
- include "MyClass.h"
int main(int argc, char *argv[]) {
vtkSmartPointer<vtkMyClass> test = vtkSmartPointer<vtkMyClass>::New();
return 0;
}
</source>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
project(NonSmartPointerMember)
find_package(VTK REQUIRED) include(${VTK_USE_FILE})
add_executable(NonSmartPointerMember NonSmartPointerMember.cxx MyClass.cxx) if(VTK_LIBRARIES)
target_link_libraries(NonSmartPointerMember ${VTK_LIBRARIES})
else()
target_link_libraries(NonSmartPointerMember vtkHybrid)
endif() </source>