1 #include "VTKViewer_Actor.h"
2 #include "VTKViewer_Transform.h"
3 #include "VTKViewer_GeometryFilter.h"
4 #include "VTKViewer_TransformFilter.h"
5 #include "VTKViewer_PassThroughFilter.h"
8 #include <vtkObjectFactory.h>
9 #include <vtkDataSetMapper.h>
10 #include <vtkPolyDataMapper.h>
11 #include <vtkRenderer.h>
12 #include <vtkMapper.h>
13 #include <vtkPolyData.h>
18 static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){
19 vtkPoints *aPoints = vtkPoints::New();
20 vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
21 aPoints->SetNumberOfPoints(iEnd);
22 for(vtkIdType i = 0; i < iEnd; i++){
23 aPoints->SetPoint(i,theSourceDataSet->GetPoint(i));
25 theGrid->SetPoints(aPoints);
32 vtkStandardNewMacro(VTKViewer_Actor);
35 VTKViewer_Actor::VTKViewer_Actor(){
36 myIsHighlighted = myIsPreselected = false;
39 myDisplayMode = myRepresentation - 1;
41 myProperty = vtkProperty::New();
42 PreviewProperty = NULL;
45 myIsResolveCoincidentTopology = true;
47 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
48 myPolygonOffsetUnits);
49 myStoreMapping = false;
50 myGeomFilter = VTKViewer_GeometryFilter::New();
52 myTransformFilter = VTKViewer_TransformFilter::New();
54 for(int i = 0; i < 6; i++)
55 myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
57 Visibility = Pickable = true;
61 VTKViewer_Actor::~VTKViewer_Actor(){
62 SetPreviewProperty(NULL);
64 myGeomFilter->UnRegisterAllOutputs();
65 myGeomFilter->Delete();
67 myTransformFilter->UnRegisterAllOutputs();
68 myTransformFilter->Delete();
70 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
72 myPassFilter[i]->UnRegisterAllOutputs();
73 myPassFilter[i]->Delete();
79 void VTKViewer_Actor::AddToRender(vtkRenderer* theRenderer){
80 theRenderer->AddActor(this);
83 void VTKViewer_Actor::RemoveFromRender(vtkRenderer* theRenderer){
84 theRenderer->RemoveActor(this);
88 void VTKViewer_Actor::SetTransform(VTKViewer_Transform* theTransform){
89 myTransformFilter->SetTransform(theTransform);
93 void VTKViewer_Actor::SetMapper(vtkMapper* theMapper){
94 InitPipeLine(theMapper);
97 void VTKViewer_Actor::InitPipeLine(vtkMapper* theMapper){
100 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
101 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
104 myGeomFilter->SetStoreMapping( myStoreMapping );
105 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
108 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
109 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
112 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
115 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
116 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
119 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
120 aMapper->SetInput(myPassFilter[anId]->GetOutput());
121 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
122 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
125 vtkLODActor::SetMapper(theMapper);
129 void VTKViewer_Actor::Render(vtkRenderer *ren, vtkMapper* m){
130 if(myIsResolveCoincidentTopology){
131 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
132 float aFactor, aUnit;
133 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
135 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
136 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
137 myPolygonOffsetUnits);
138 vtkLODActor::Render(ren,m);
140 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
141 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
143 vtkLODActor::Render(ren,m);
148 void VTKViewer_Actor::SetResolveCoincidentTopology(bool theIsResolve) {
149 myIsResolveCoincidentTopology = theIsResolve;
152 void VTKViewer_Actor::SetPolygonOffsetParameters(float factor, float units){
153 myPolygonOffsetFactor = factor;
154 myPolygonOffsetUnits = units;
157 void VTKViewer_Actor::GetPolygonOffsetParameters(float& factor, float& units){
158 factor = myPolygonOffsetFactor;
159 units = myPolygonOffsetUnits;
163 vtkDataSet* VTKViewer_Actor::GetInput(){
164 return myPassFilter.front()->GetOutput();
168 unsigned long int VTKViewer_Actor::GetMTime(){
169 unsigned long mTime = this->Superclass::GetMTime();
170 unsigned long time = myTransformFilter->GetMTime();
171 mTime = ( time > mTime ? time : mTime );
172 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
173 time = aDataSet->GetMTime();
174 mTime = ( time > mTime ? time : mTime );
180 void VTKViewer_Actor::SetRepresentation(int theMode) {
181 switch(myRepresentation){
184 myProperty->DeepCopy(GetProperty());
189 GetProperty()->DeepCopy(myProperty);
193 GetProperty()->SetAmbient(1.0);
194 GetProperty()->SetDiffuse(0.0);
195 GetProperty()->SetSpecular(0.0);
199 myGeomFilter->SetInside(true);
200 GetProperty()->SetRepresentation(1);
203 GetProperty()->SetPointSize(VTKViewer_POINT_SIZE);
205 GetProperty()->SetRepresentation(theMode);
206 myGeomFilter->SetInside(false);
208 myRepresentation = theMode;
211 int VTKViewer_Actor::GetRepresentation(){
212 return myRepresentation;
216 vtkCell* VTKViewer_Actor::GetElemCell(int theObjID){
217 return GetInput()->GetCell(theObjID);
221 float* VTKViewer_Actor::GetNodeCoord(int theObjID){
222 return GetInput()->GetPoint(theObjID);
226 //=================================================================================
227 // function : GetObjDimension
228 // purpose : Return object dimension.
229 // Virtual method shoulb be redifined by derived classes
230 //=================================================================================
231 int VTKViewer_Actor::GetObjDimension( const int theObjId )
233 if ( vtkCell* aCell = GetElemCell(theObjId) )
234 return aCell->GetCellDimension();
239 bool VTKViewer_Actor::IsInfinitive(){
244 void VTKViewer_Actor::SetOpacity(float theOpacity){
245 myOpacity = theOpacity;
246 GetProperty()->SetOpacity(theOpacity);
249 float VTKViewer_Actor::GetOpacity(){
254 void VTKViewer_Actor::SetColor(float r,float g,float b){
255 GetProperty()->SetColor(r,g,b);
258 void VTKViewer_Actor::GetColor(float& r,float& g,float& b){
260 GetProperty()->GetColor(aColor);
267 int VTKViewer_Actor::getDisplayMode(){
268 return myDisplayMode;
271 void VTKViewer_Actor::setDisplayMode(int theMode){
272 SetRepresentation(theMode+1);
273 myDisplayMode = GetRepresentation() - 1;