1 /*=========================================================================
5 Author : Joel Schaerer (joel.schaerer@insa-lyon.fr)
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, version 3 of the License.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 =========================================================================*/
25 #include "vvMeshActor.h"
26 #include "clitkCommon.h"
27 #include <vtkPolyDataMapper.h>
28 #include <vtkMarchingSquares.h>
29 #include <vtkImageData.h>
31 #include <vtkProperty.h>
35 vvMeshActor::vvMeshActor() :
36 mCutDimension(NULL), mMesh(NULL),
37 mMarching(NULL), mMapper(NULL),
39 mSuperpostionMode(false), mTimeSlice(0)
42 vvMeshActor::~vvMeshActor()
49 void vvMeshActor::Init(vvMesh::Pointer mesh,int time_slice,vvImage::Pointer vf)
53 mMarching=vtkMarchingSquares::New();
54 mTimeSlice=time_slice;
55 if (static_cast<unsigned int>(time_slice)<mMesh->GetNumberOfMeshes())
56 mMarching->SetInput(mMesh->GetMask(time_slice));
58 mMarching->SetInput(mMesh->GetMask(0));
59 mMarching->SetValue(0,0.5);
60 //mMarching->Update();
62 mMapper=vtkPolyDataMapper::New();
63 mMapper->SetInput(mMarching->GetOutput());
64 //The following line allows to display the contour over the image
65 //(http://www.nabble.com/What-happens-when-two-actors-are-at-the-same-depth--td23175458.html)
66 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
67 mActor=vtkActor::New();
68 mActor->SetMapper(mMapper);
69 mActor->SetPickable(false);
70 mActor->GetProperty()->EdgeVisibilityOn();
71 mActor->GetProperty()->SetEdgeColor(mMesh->r,mMesh->g,mMesh->b);
72 mActor->GetProperty()->SetLineWidth(2.);
75 void vvMeshActor::SetCutSlice(double slice)
79 if (static_cast<unsigned int>(mTimeSlice)<mMesh->GetNumberOfMasks())
80 mask=mMesh->GetMask(mTimeSlice);
82 mask=mMesh->GetMask(0);
83 int* dims=mask->GetDimensions();
84 int mask_slice=(slice-mask->GetOrigin()[mCutDimension])/mask->GetSpacing()[mCutDimension];
85 switch (mCutDimension)
88 mMarching->SetImageRange(mask_slice,mask_slice,0,dims[1],0,dims[2]);
91 mMarching->SetImageRange(0,dims[0],mask_slice,mask_slice,0,dims[2]);
94 mMarching->SetImageRange(0,dims[0],0,dims[1],mask_slice,mask_slice);
102 void vvMeshActor::SetTimeSlice(int time)
105 if (static_cast<unsigned int>(time)<mMesh->GetNumberOfMasks())
106 mMarching->SetInput(mMesh->GetMask(time));
108 mMarching->SetInput(mMesh->GetMask(0));
109 SetCutSlice(mCutSlice); //We need to find the new mask cut slice,
110 //since masks do not all have the same origin
113 void vvMeshActor::SetSlicingOrientation(unsigned int d)
118 void vvMeshActor::ToggleSuperposition()
120 DD("Warning: superposition not implemented");
121 // std::cout << "vvMeshActor::ToggleSuperposition size = " << mMeshes.size() << std::endl;
122 if (! mSuperpostionMode && mMesh->GetNumberOfMeshes() > 1)
124 mSuperpostionMode=true;
128 mSuperpostionMode=false;