1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkHyperOctreeClipCutPointsGrabber.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkHyperOctreeClipCutPointsGrabber.h"
#include "vtkObjectFactory.h"
#include "vtkOrderedTriangulator.h"
#include <set>
#include "vtkPolygon.h"
#include <cassert>
#include "vtkPoints.h"
vtkStandardNewMacro(vtkHyperOctreeClipCutPointsGrabber);
class vtkHyperOctreeIdSet // Pimpl idiom
{
public:
std::set<vtkIdType> Set;
};
//-----------------------------------------------------------------------------
// Description:
// Default constructor.
vtkHyperOctreeClipCutPointsGrabber::vtkHyperOctreeClipCutPointsGrabber()
{
this->Triangulator=vtkOrderedTriangulator::New();
this->IdSet=new vtkHyperOctreeIdSet;
this->Polygon=0;
this->Dimension=3;
}
//-----------------------------------------------------------------------------
// Description:
// Destructor.
vtkHyperOctreeClipCutPointsGrabber::~vtkHyperOctreeClipCutPointsGrabber()
{
if(this->Triangulator!=0)
{
this->Triangulator->UnRegister(this);
delete this->IdSet;
}
if(this->Polygon!=0)
{
this->Polygon->UnRegister(this);
}
}
//-----------------------------------------------------------------------------
// Description:
// Set the dimension of the hyperoctree.
// \pre valid_dim: (dim==2 || dim==3)
// \post is_set: GetDimension()==dim
void vtkHyperOctreeClipCutPointsGrabber::SetDimension(int dim)
{
assert("pre: valid_dim" && (dim==2 || dim==3));
if(dim!=this->Dimension)
{
if(dim==3)
{
this->Polygon->UnRegister(this);
this->Polygon=0;
this->Triangulator=vtkOrderedTriangulator::New();
this->IdSet=new vtkHyperOctreeIdSet;
}
else
{
this->Triangulator->UnRegister(this);
this->Triangulator=0;
delete this->IdSet;
this->IdSet=0;
this->Polygon=vtkPolygon::New();
}
this->Dimension=dim;
}
assert("post: is_set" && GetDimension()==dim);
}
//-----------------------------------------------------------------------------
// Description:
// Initialize the points insertion scheme.
// Actually, it is just a trick to initialize the IdSet from the filter.
// The IdSet class cannot be shared with the filter because it is a Pimpl.
// It is used by clip,cut and contour filters to build the points
// that lie on an hyperoctant.
// \pre only_in_3d: GetDimension()==3
void vtkHyperOctreeClipCutPointsGrabber::InitPointInsertion()
{
assert("pre: only_in_3d" && this->GetDimension()==3);
this->IdSet->Set.clear();
}
//-----------------------------------------------------------------------------
// Description:
// Insert a point, assuming the point is unique and does not require a
// locator. Tt does not mean it does not use a locator. It just mean that
// some implementation may skip the use of a locator.
void vtkHyperOctreeClipCutPointsGrabber::InsertPoint(vtkIdType ptId,
double pt[3],
double pcoords[3],
int vtkNotUsed(ijk)[3])
{
this->Triangulator->InsertPoint(ptId,pt,pcoords,0);
}
//-----------------------------------------------------------------------------
// Description:
// Insert a point using a locator.
void vtkHyperOctreeClipCutPointsGrabber::InsertPointWithMerge(
vtkIdType ptId,
double pt[3],
double pcoords[3],
int vtkNotUsed(ijk)[3])
{
if(this->IdSet->Set.find(ptId)==this->IdSet->Set.end()) // not find
{
this->IdSet->Set.insert(ptId);
this->Triangulator->InsertPoint(ptId,pt,pcoords,0);
}
}
//-----------------------------------------------------------------------------
// Description:
// Insert a point in the quadtree case.
void vtkHyperOctreeClipCutPointsGrabber::InsertPoint2D(double pt[3],
int vtkNotUsed(ijk)[3])
{
this->Polygon->GetPointIds()->InsertNextId(
this->Polygon->GetPointIds()->GetNumberOfIds());
this->Polygon->GetPoints()->InsertNextPoint(pt);
}
//-----------------------------------------------------------------------------
// Description:
// Return the ordered triangulator.
vtkOrderedTriangulator *vtkHyperOctreeClipCutPointsGrabber::GetTriangulator()
{
return this->Triangulator;
}
//-----------------------------------------------------------------------------
// Description:
// Return the polygon.
vtkPolygon *vtkHyperOctreeClipCutPointsGrabber::GetPolygon()
{
return this->Polygon;
}
//-----------------------------------------------------------------------------
void vtkHyperOctreeClipCutPointsGrabber::PrintSelf(ostream& os,
vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|