/usr/include/vtk-6.3/vtkPointAccumulator.hxx is in libvtk6-dev 6.3.0+dfsg1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkPointAccumulator.hxx
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.
=========================================================================*/
// .NAME vtkPointAccumulator - Container class that manages appending data arrays of points.
// .SECTION Description
//
// The template types are T_CPP for the c++ data type and T_VTK for
// the VTK data type. Eg: if T_CCP==double the T_VTK must be
// vtkDoubleArray. The main difference between the way this
// works and if you were to do the same thing with a data array is
// that here the memory grows by exactly what is needed, and
// in VTK data arrays the memory will grow by at least twice
// what is requested.
#ifndef vtkPointAccumulator_hxx
#define vtkPointAccumulator_hxx
#include <exception>
#include "vtkPoints.h"
template<typename T_CPP, class T_VTK>
class vtkPointAccumulator
{
public:
vtkPointAccumulator()
{
this->PtStore=0;
this->NPts=0;
}
~vtkPointAccumulator()
{
this->Clear();
}
// Description:
// Free resources and mark as empty.
void Clear()
{
if (this->PtStore!=0)
{
free(this->PtStore);
}
this->PtStore=0;
this->NPts=0;
}
// Description:
// Test if there is anything in the store.
bool Empty()
{
return this->NPts==0;
}
// Description:
// Extend the internal store and get a pointer to
// the newly added memory.
T_CPP *Expand(vtkIdType n)
{
const int bytesPerPoint=3*sizeof(T_CPP);
// extend
vtkIdType newNPts=this->NPts+n;
T_CPP *newPointStore
= static_cast<T_CPP *>(realloc(this->PtStore,newNPts*bytesPerPoint));
if (newPointStore==0)
{
#ifndef NDEBUG
abort();
#else
throw std::bad_alloc();
#endif
}
// mark begin of new
T_CPP *writePointer=newPointStore+3*this->NPts;
// update
this->PtStore=newPointStore;
this->NPts=newNPts;
return writePointer;
}
// Description:
// Adds an array of points to the end of
// the internal store.
void Accumulate(T_CPP *pts, vtkIdType n)
{
// extend
T_CPP *writePointer=this->Expand(n);
// copy at end
const int bytesPerPoint=3*sizeof(T_CPP);
memcpy(writePointer,pts,n*bytesPerPoint);
}
// Description:
// Adds an array of points at the end of
// the internal store.
void Accumulate(T_VTK *pts)
{
this->Accumulate(pts->GetPointer(0),pts->GetNumberOfTuples());
}
// Description:
// Creates a vtkPoints data structure from
// the internal store. Caller to delete the points.
vtkPoints *BuildVtkPoints()
{
T_VTK *da=T_VTK::New();
da->SetNumberOfComponents(3);
da->SetArray(this->PtStore,3*this->NPts,1);
vtkPoints *pts=vtkPoints::New();
pts->SetData(da);
da->Delete();
return pts;
}
// Description:
// Compute axis-aligned bounding box. An exhaustive search is made
// through points every time. It's calllers responsibility to use
// sparingly.
void GetBounds(double bounds[6])
{
// Prepare
for (int q=0; q<3; ++q)
{
bounds[q]=static_cast<double>(this->PtStore[q]);
bounds[q+1]=static_cast<double>(this->PtStore[q+1]);
}
// Search
for (vtkIdType i=1; i<this->NPts; ++i)
{
double pt[3];
vtkIdType ptIdx=3*i;
pt[0]=static_cast<double>(this->PtStore[ptIdx]);
pt[1]=static_cast<double>(this->PtStore[ptIdx+1]);
pt[2]=static_cast<double>(this->PtStore[ptIdx+2]);
if (pt[0]<bounds[0]) bounds[0]=pt[0];
if (pt[0]>bounds[1]) bounds[1]=pt[0];
if (pt[1]<bounds[2]) bounds[2]=pt[1];
if (pt[1]>bounds[3]) bounds[3]=pt[1];
if (pt[2]<bounds[4]) bounds[4]=pt[2];
if (pt[2]>bounds[5]) bounds[5]=pt[2];
}
}
// Description:
// Return the number of points currently in the point store.
vtkIdType GetNumberOfPoints()
{
return this->NPts;
}
// Description:
// Print the contents of the internal store.
void Print()
{
T_CPP *pBuf=this->PtStore;
for (int i=0; i<this->NPts; ++i)
{
cerr << i << " (" << pBuf[0];
for (int q=1; q<3; ++q)
{
cerr << ", " << pBuf[q];
}
cerr << ")" << endl;
pBuf+=3;
}
}
private:
vtkPointAccumulator(const vtkPointAccumulator &); // Not implemented
vtkPointAccumulator &operator=(const vtkPointAccumulator &); // Not implemented
T_CPP *PtStore;
vtkIdType NPts;
};
#endif
|