#include "VTKViewer_Transform.h"
#include "VTKViewer_Utilities.h"
-#include <vtkCamera.h>
-#include <vtkRenderer.h>
-#include <vtkTextProperty.h>
-#include <vtkObjectFactory.h>
+#include <vtkAbstractVolumeMapper.h>
#include <vtkCallbackCommand.h>
-
+#include <vtkCamera.h>
+#include <vtkDataSet.h>
+#include <vtkGenericCell.h>
+#include <vtkMapper.h>
#include <vtkPicker.h>
#include <vtkPointPicker.h>
-#include <vtkCellPicker.h>
-
#include <vtkProperty.h>
+#include <vtkRenderer.h>
+#include <vtkTextProperty.h>
+#include <vtkObjectFactory.h>
// undefining min and max because CASCADE's defines them and
// it clashes with std::min(), std::max() included in utilities.h
#undef min
#undef max
-
vtkStandardNewMacro(SVTK_Renderer);
+vtkStandardNewMacro(SVTK_CellPicker);
/*!
Constructor
myPriority(0.0),
myEventCallbackCommand(vtkCallbackCommand::New()),
myPointPicker(vtkPointPicker::New()),
- myCellPicker(vtkCellPicker::New()),
+ myCellPicker(SVTK_CellPicker::New()),
myPointRectPicker(SVTK_RectPicker::New()),
myCellRectPicker(SVTK_RectPicker::New()),
myPreHighlightProperty(vtkProperty::New()),
aCamera->SetFocalPoint(0,0,0);
this->OnFitAll();
}
+
+/*!
+ SVTK_CellPicker constructor
+*/
+SVTK_CellPicker::SVTK_CellPicker()
+{
+ this->Cell = vtkGenericCell::New();
+}
+
+/*!
+ SVTK_CellPicker destructor
+*/
+SVTK_CellPicker::~SVTK_CellPicker()
+{
+ this->Cell->Delete();
+}
+
+/*!
+ Redefined virtual method of the vtkCellPicker class
+*/
+double SVTK_CellPicker::IntersectWithLine(double p1[3], double p2[3], double tol,
+ vtkAssemblyPath *path,
+ vtkProp3D *prop3D,
+ vtkAbstractMapper3D *m)
+{
+ vtkIdType numCells, cellId, minCellId;
+ int i, minSubId, subId;
+ double x[3], tMin, t, pcoords[3], minXYZ[3], minPcoords[3];
+ vtkDataSet *input;
+ vtkMapper *mapper;
+ vtkAbstractVolumeMapper *volumeMapper;
+
+ // Get the underlying dataset
+ if ( (mapper=vtkMapper::SafeDownCast(m)) != NULL )
+ {
+ input = mapper->GetInput();
+ }
+ else if ( (volumeMapper=vtkAbstractVolumeMapper::SafeDownCast(m)) != NULL )
+ {
+ input = volumeMapper->GetDataSetInput();
+ }
+ else
+ {
+ return VTK_DOUBLE_MAX;
+ }
+
+ if ( (numCells = input->GetNumberOfCells()) < 1 )
+ {
+ return 2.0;
+ }
+
+ // Intersect each cell with ray. Keep track of one closest to
+ // the eye (within the tolerance tol) and within the clipping range).
+ // Note that we fudge the "closest to" (tMin+this->Tolerance) a little and
+ // keep track of the cell with the best pick based on parametric
+ // coordinate (pick the minimum, maximum parametric distance). This
+ // breaks ties in a reasonable way when cells are the same distance
+ // from the eye (like cells lying on a 2D plane).
+ //
+ minCellId = -1;
+ minSubId = -1;
+ pcoords[0] = pcoords[1] = pcoords[2] = 0;
+ double pDistMin=VTK_DOUBLE_MAX, pDist;
+ for (tMin=VTK_DOUBLE_MAX,cellId=0; cellId<numCells; cellId++)
+ {
+ input->GetCell(cellId, this->Cell);
+
+ if ( this->Cell->IntersectWithLine(p1, p2, tol, t, x, pcoords, subId)
+ && t <= (tMin+this->Tolerance) )
+ {
+ pDist = this->Cell->GetParametricDistance(pcoords);
+ // This is the only difference of this method from the vtkCellPicker's one
+ static double aTolerance = 1E-7;
+ //if ( pDist < pDistMin || (pDist == pDistMin && t < tMin ) )
+ if ( pDist < pDistMin || (pDist == pDistMin && t < tMin + aTolerance ) )
+ {
+ minCellId = cellId;
+ minSubId = subId;
+ for (i=0; i<3; i++)
+ {
+ minXYZ[i] = x[i];
+ minPcoords[i] = pcoords[i];
+ }
+ tMin = t;
+ pDistMin = pDist;
+// cout << "cell id: " << minCellId << "\n";
+ }//if minimum, maximum
+ }//if a close cell
+ }//for all cells
+
+ // Now compare this against other actors.
+ //
+ if ( minCellId>(-1) && tMin < this->GlobalTMin )
+ {
+ this->MarkPicked(path, prop3D, m, tMin, minXYZ);
+ this->CellId = minCellId;
+ this->SubId = minSubId;
+ for (i=0; i<3; i++)
+ {
+ this->PCoords[i] = minPcoords[i];
+ }
+ vtkDebugMacro("Picked cell id= " << minCellId);
+ }
+ return tMin;
+}
{
for ( i=0; i < numFacePts; i++)
aNewPts[i] = pts[faceVerts[i]];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
{
for ( i=0; i < numFacePts; i++)
aNewPts[i] = pts[faceVerts[PixelConvert[i]]];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
{
for ( i=0; i < numFacePts; i++)
aNewPts[i] = pts[faceVerts[i]];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
{
for ( i=0; i < numFacePts; i++)
aNewPts[i] = pts[faceVerts[i]];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
{
for ( i=0; i < numFacePts; i++)
aNewPts[i] = pts[faceVerts[i]];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
for (i=0; i < pts->GetNumberOfIds(); i+=2) {
aNewPts[0] = pts->GetId(i);
aNewPts[1] = pts->GetId(i+1);
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[0] = pts->GetId(i);
aNewPts[1] = pts->GetId(i+1);
aNewPts[2] = pts->GetId(i+2);
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[0] = pts->GetId(i);
aNewPts[1] = pts->GetId(i+1);
aNewPts[2] = pts->GetId(i+2);
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[2] = pts[1];
aNewPts[1] = pts[2];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[4] = pts[2];
aNewPts[5] = pts[5];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[6] = pts[3];
aNewPts[7] = pts[7];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[4] = pts[2];
aNewPts[5] = pts[6];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[4] = pts[1];
aNewPts[5] = pts[4];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[4] = pts[2];
aNewPts[5] = pts[5];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[4] = pts[0];
aNewPts[5] = pts[6];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[3] = pts[7];
aNewPts[4] = pts[2];
aNewPts[5] = pts[8];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[3] = pts[10];
aNewPts[4] = pts[5];
aNewPts[5] = pts[11];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[5] = pts[11];
aNewPts[6] = pts[3];
aNewPts[7] = pts[12];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[5] = pts[14];
aNewPts[6] = pts[2];
aNewPts[7] = pts[7];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[5] = pts[13];
aNewPts[6] = pts[1];
aNewPts[7] = pts[6];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
outputCD->CopyData(cd,cellId,newCellId);
aNewPts[6] = pts[4];
aNewPts[7] = pts[16];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[6] = pts[5];
aNewPts[7] = pts[17];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[6] = pts[6];
aNewPts[7] = pts[18];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[6] = pts[7];
aNewPts[7] = pts[19];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[6] = pts[3];
aNewPts[7] = pts[11];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);
aNewPts[6] = pts[7];
aNewPts[7] = pts[15];
- newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+ newCellId = output->InsertNextCell(aCellType,numFacePts,(vtkIdType*)aNewPts);
if(myStoreMapping)
myVTK2ObjIds.push_back(cellId);