33 #include "fwRenderVTK/vtk/fwVtkCellPicker.hpp" 35 #include <boost/assign.hpp> 37 #include <vtkAbstractVolumeMapper.h> 38 #include <vtkGenericCell.h> 39 #include <vtkImageData.h> 40 #include <vtkInstantiator.h> 41 #include <vtkMapper.h> 43 #include <vtkObjectFactory.h> 44 #include <vtkPolyData.h> 50 fwVtkCellPicker::fwVtkCellPicker()
54 for (
int i = 0; i < 3; i++)
56 this->PCoords[i] = 0.0;
58 this->Cell = vtkGenericCell::New();
63 fwVtkCellPicker::~fwVtkCellPicker()
70 double fwVtkCellPicker::IntersectWithLine(
double p1[3],
double p2[3],
double tol,
71 vtkAssemblyPath* path,
73 vtkAbstractMapper3D* m)
75 vtkIdType numCells, cellId, minCellId;
76 int i, minSubId, subId;
77 double x[3], tMin, t, pcoords[3], minXYZ[3], minPcoords[3];
80 vtkAbstractVolumeMapper* volumeMapper;
83 if ( (mapper = vtkMapper::SafeDownCast(m)) != NULL )
85 input = mapper->GetInput();
87 else if ( (volumeMapper = vtkAbstractVolumeMapper::SafeDownCast(m)) != NULL )
89 input = volumeMapper->GetDataSetInput();
93 return VTK_DOUBLE_MAX;
96 if ( (numCells = input->GetNumberOfCells()) < 1 )
111 pcoords[0] = pcoords[1] = pcoords[2] = 0;
112 double pDistMin = VTK_DOUBLE_MAX, pDist;
113 for (tMin = VTK_DOUBLE_MAX, cellId = 0; cellId < numCells; cellId++)
115 input->GetCell(cellId, this->Cell);
117 if ( this->Cell->IntersectWithLine(p1, p2, tol, t, x, pcoords, subId)
118 && t <= (tMin+this->Tolerance) )
120 pDist = this->Cell->GetParametricDistance(pcoords);
121 if ( pDist < pDistMin || (pDist == pDistMin && t < tMin) )
125 for (i = 0; i < 3; i++)
128 minPcoords[i] = pcoords[i];
137 if ( minCellId > (-1) && tMin < this->GlobalTMin )
139 this->MarkPicked(path, prop3D, m, tMin, minXYZ);
140 this->CellId = minCellId;
141 this->SubId = minSubId;
142 for (i = 0; i < 3; i++)
144 this->PCoords[i] = minPcoords[i];
146 vtkDebugMacro(
"Picked cell id= " << minCellId);
153 void fwVtkCellPicker::Initialize()
157 for (
int i = 0; i < 3; i++)
159 this->PCoords[i] = 0.0;
161 this->fwVtkPicker::Initialize();
166 void fwVtkCellPicker::PrintSelf(ostream& os, vtkIndent indent)
168 this->Superclass::PrintSelf(os, indent);
170 os << indent <<
"Cell Id: " << this->CellId <<
"\n";
171 os << indent <<
"SubId: " << this->SubId <<
"\n";
172 os << indent <<
"PCoords: (" << this->PCoords[0] <<
", " 173 << this->PCoords[1] <<
", " << this->PCoords[2] <<
")\n";
178 fwVtkCellPicker::PickedCellType fwVtkCellPicker::GetPickedCellIds(
double p1[3],
double p2[3], vtkPolyData* polydata)
182 if ( this->PickPolyData(p1, p2, polydata) )
184 double* intersec = this->GetPickPosition();
187 for(
unsigned int i = 0; i < 3; i++)
189 point[i] = intersec[i];
191 res.push_back( std::make_pair( this->GetCellId(), point) );
197 this->GetPickPosition(p3a);
198 this->GetPickPosition(p3b);
200 for (
int i = 0; i < 3; i++)
202 ray[i] = p2[i] - p1[i];
205 vtkMath::Normalize(ray);
207 for (
int i = 0; i < 3; i++)
214 ::boost::assign::push_back(res).range( this->GetPickedCellIds(p1, p3a, polydata) );
215 ::boost::assign::push_back(res).range( this->GetPickedCellIds(p3b, p2, polydata) );