1 #include "vvMeshActor.h"
2 #include "clitkCommon.h"
3 #include <vtkPolyDataMapper.h>
4 #include <vtkMarchingSquares.h>
5 #include <vtkImageData.h>
7 #include <vtkProperty.h>
11 vvMeshActor::vvMeshActor() :
12 mCutDimension(NULL), mMesh(NULL),
13 mMarching(NULL), mMapper(NULL),
15 mSuperpostionMode(false), mTimeSlice(0)
18 vvMeshActor::~vvMeshActor()
25 void vvMeshActor::Init(vvMesh::Pointer mesh,int time_slice,vvImage::Pointer vf)
29 mMarching=vtkMarchingSquares::New();
30 mTimeSlice=time_slice;
31 if (static_cast<unsigned int>(time_slice)<mMesh->GetNumberOfMeshes())
32 mMarching->SetInput(mMesh->GetMask(time_slice));
34 mMarching->SetInput(mMesh->GetMask(0));
35 mMarching->SetValue(0,0.5);
36 //mMarching->Update();
38 mMapper=vtkPolyDataMapper::New();
39 mMapper->SetInput(mMarching->GetOutput());
40 //The following line allows to display the contour over the image
41 //(http://www.nabble.com/What-happens-when-two-actors-are-at-the-same-depth--td23175458.html)
42 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
43 mActor=vtkActor::New();
44 mActor->SetMapper(mMapper);
45 mActor->SetPickable(false);
46 mActor->GetProperty()->EdgeVisibilityOn();
47 mActor->GetProperty()->SetEdgeColor(mMesh->r,mMesh->g,mMesh->b);
48 mActor->GetProperty()->SetLineWidth(2.);
51 void vvMeshActor::SetCutSlice(double slice)
55 if (static_cast<unsigned int>(mTimeSlice)<mMesh->GetNumberOfMasks())
56 mask=mMesh->GetMask(mTimeSlice);
58 mask=mMesh->GetMask(0);
59 int* dims=mask->GetDimensions();
60 int mask_slice=(slice-mask->GetOrigin()[mCutDimension])/mask->GetSpacing()[mCutDimension];
61 switch (mCutDimension)
64 mMarching->SetImageRange(mask_slice,mask_slice,0,dims[1],0,dims[2]);
67 mMarching->SetImageRange(0,dims[0],mask_slice,mask_slice,0,dims[2]);
70 mMarching->SetImageRange(0,dims[0],0,dims[1],mask_slice,mask_slice);
78 void vvMeshActor::SetTimeSlice(int time)
81 if (static_cast<unsigned int>(time)<mMesh->GetNumberOfMasks())
82 mMarching->SetInput(mMesh->GetMask(time));
84 mMarching->SetInput(mMesh->GetMask(0));
85 SetCutSlice(mCutSlice); //We need to find the new mask cut slice,
86 //since masks do not all have the same origin
89 void vvMeshActor::SetSlicingOrientation(unsigned int d)
94 void vvMeshActor::ToggleSuperposition()
96 DD("Warning: superposition not implemented");
97 // std::cout << "vvMeshActor::ToggleSuperposition size = " << mMeshes.size() << std::endl;
98 if (! mSuperpostionMode && mMesh->GetNumberOfMeshes() > 1)
100 mSuperpostionMode=true;
104 mSuperpostionMode=false;