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 /*!Constructor.Initialize default parameters.*/
36 VTKViewer_Actor::VTKViewer_Actor(){
37 myIsHighlighted = myIsPreselected = false;
40 myDisplayMode = myRepresentation - 1;
42 myProperty = vtkProperty::New();
43 PreviewProperty = NULL;
46 myIsResolveCoincidentTopology = true;
48 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
49 myPolygonOffsetUnits);
50 myStoreMapping = false;
51 myGeomFilter = VTKViewer_GeometryFilter::New();
53 myTransformFilter = VTKViewer_TransformFilter::New();
55 for(int i = 0; i < 6; i++)
56 myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
58 Visibility = Pickable = true;
63 VTKViewer_Actor::~VTKViewer_Actor(){
64 SetPreviewProperty(NULL);
66 myGeomFilter->UnRegisterAllOutputs();
67 myGeomFilter->Delete();
69 myTransformFilter->UnRegisterAllOutputs();
70 myTransformFilter->Delete();
72 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
74 myPassFilter[i]->UnRegisterAllOutputs();
75 myPassFilter[i]->Delete();
81 /*!Add VTKViewer_Actor to renderer.
82 *\param theRenderer - vtkRenderer
84 void VTKViewer_Actor::AddToRender(vtkRenderer* theRenderer){
85 theRenderer->AddActor(this);
88 /*!Remove VTKViewer_Actor from renderer.
89 *\param theRenderer - vtkRenderer
91 void VTKViewer_Actor::RemoveFromRender(vtkRenderer* theRenderer){
92 theRenderer->RemoveActor(this);
95 /*!Add transformation to transform filter.
96 *\param theTransform - transformation.
98 void VTKViewer_Actor::SetTransform(VTKViewer_Transform* theTransform){
99 myTransformFilter->SetTransform(theTransform);
102 /*!Set mapper to pipeline.\n
103 *Call method for pipeline initialization.
104 *\param theMapper - mapper
106 void VTKViewer_Actor::SetMapper(vtkMapper* theMapper){
107 InitPipeLine(theMapper);
110 /*!Initialize sequence of filters for mapper, if \a theMapper is not null.
111 *\param theMapper - mapper
113 void VTKViewer_Actor::InitPipeLine(vtkMapper* theMapper){
116 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
117 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
120 myGeomFilter->SetStoreMapping( myStoreMapping );
121 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
124 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
125 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
128 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
131 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
132 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
135 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
136 aMapper->SetInput(myPassFilter[anId]->GetOutput());
137 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
138 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
141 vtkLODActor::SetMapper(theMapper);
145 void VTKViewer_Actor::Render(vtkRenderer *ren, vtkMapper* m){
146 if(myIsResolveCoincidentTopology){
147 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
148 float aFactor, aUnit;
149 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
151 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
152 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
153 myPolygonOffsetUnits);
154 vtkLODActor::Render(ren,m);
156 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
157 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
159 vtkLODActor::Render(ren,m);
163 /*!Set flag myIsResolveCoincidentTopology to \a theIsResolve.
164 *\param theIsResolve - bool flag.
166 void VTKViewer_Actor::SetResolveCoincidentTopology(bool theIsResolve) {
167 myIsResolveCoincidentTopology = theIsResolve;
170 /*!Sets polygon offset factor and polygon offset units.
171 *\param factor - float factor
172 *\param units - float units
174 void VTKViewer_Actor::SetPolygonOffsetParameters(float factor, float units){
175 myPolygonOffsetFactor = factor;
176 myPolygonOffsetUnits = units;
179 /*!Gets polygon offset factor and polygon offset units.
180 *\param factor - output float
181 *\param units - output float
183 void VTKViewer_Actor::GetPolygonOffsetParameters(float& factor, float& units){
184 factor = myPolygonOffsetFactor;
185 units = myPolygonOffsetUnits;
189 /*!Get input data set.
190 *\retval vtkDataSet pointer.
192 vtkDataSet* VTKViewer_Actor::GetInput(){
193 return myPassFilter.front()->GetOutput();
196 /*!Get modification time.
197 *\retval time - unsigned long.
199 unsigned long int VTKViewer_Actor::GetMTime(){
200 unsigned long mTime = this->Superclass::GetMTime();
201 unsigned long time = myTransformFilter->GetMTime();
202 mTime = ( time > mTime ? time : mTime );
203 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
204 time = aDataSet->GetMTime();
205 mTime = ( time > mTime ? time : mTime );
210 /*!Set representation mode.
211 *\param theMode - int.
213 void VTKViewer_Actor::SetRepresentation(int theMode) {
214 switch(myRepresentation){
217 myProperty->DeepCopy(GetProperty());
222 GetProperty()->DeepCopy(myProperty);
226 GetProperty()->SetAmbient(1.0);
227 GetProperty()->SetDiffuse(0.0);
228 GetProperty()->SetSpecular(0.0);
232 myGeomFilter->SetInside(true);
233 GetProperty()->SetRepresentation(1);
236 GetProperty()->SetPointSize(VTKViewer_POINT_SIZE);
238 GetProperty()->SetRepresentation(theMode);
239 myGeomFilter->SetInside(false);
241 myRepresentation = theMode;
244 /*!Get representation.
245 *\retval representation mode.
247 int VTKViewer_Actor::GetRepresentation(){
248 return myRepresentation;
251 /*!Get VTK cell by object ID.
252 *\param theObjID - object ID.
253 *\retval vtkCell pointer.
255 vtkCell* VTKViewer_Actor::GetElemCell(int theObjID){
256 return GetInput()->GetCell(theObjID);
259 /*!Get node coordinates by node ID.
260 *\param theObjID - node ID.
261 *\retval float array of coordinates.
262 * \li array[0] - X coordinate.
263 * \li array[1] - Y coordinate.
264 * \li array[2] - Z coordinate.
266 float* VTKViewer_Actor::GetNodeCoord(int theObjID){
267 return GetInput()->GetPoint(theObjID);
271 //=================================================================================
272 // function : GetObjDimension
273 /*! purpose : Return object dimension.\n
274 * Virtual method shoulb be redifined by derived classes
275 *\param theObjId - object ID.
277 //=================================================================================
278 int VTKViewer_Actor::GetObjDimension( const int theObjId )
280 if ( vtkCell* aCell = GetElemCell(theObjId) )
281 return aCell->GetCellDimension();
285 /*!Get infinite flag*/
286 bool VTKViewer_Actor::IsInfinitive(){
290 /*!Set property - opacity.
291 *\param theOpacity - new apacity
293 void VTKViewer_Actor::SetOpacity(float theOpacity){
294 myOpacity = theOpacity;
295 GetProperty()->SetOpacity(theOpacity);
298 /*!Get property - opacity.
299 *\retval float value.
301 float VTKViewer_Actor::GetOpacity(){
305 /*!Set property - color
306 *\param r - float Red value
307 *\param g - float Green value
308 *\param b - float Blue value
310 void VTKViewer_Actor::SetColor(float r,float g,float b){
311 GetProperty()->SetColor(r,g,b);
314 /*!Get property - color
315 *\param r - output float Red value
316 *\param g - output float Green value
317 *\param b - output float Blue value
319 void VTKViewer_Actor::GetColor(float& r,float& g,float& b){
321 GetProperty()->GetColor(aColor);
330 int VTKViewer_Actor::getDisplayMode(){
331 return myDisplayMode;
335 *\param theMode - integer value.
337 void VTKViewer_Actor::setDisplayMode(int theMode){
338 SetRepresentation(theMode+1);
339 myDisplayMode = GetRepresentation() - 1;