6#include <vtkInformation.h>
7#include <vtkInformationVector.h>
10#include <vtkCellData.h>
11#include <vtkDataSet.h>
12#include <vtkUnstructuredGrid.h>
13#include <vtkVersionMacros.h>
15#include <vtkFloatArray.h>
16#include <vtkIdTypeArray.h>
25 vtkInformation *info) {
28 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
33 vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkUnstructuredGrid");
40 vtkInformation *info) {
44 info->Set(vtkDataObject::DATA_TYPE_NAME(),
"vtkUnstructuredGrid");
53 vtkInformationVector **iVec,
54 vtkInformationVector *oVec) {
56 _outFld = vtkUnstructuredGrid::GetData(oVec, 0);
57 _outPts = vtkUnstructuredGrid::GetData(oVec, 1);
62 vtkUnstructuredGrid::GetData(iVec[2])))
79 auto scalars = GetInputArrayToProcess(0, dataset);
83 const double radius = ui_spherical ? -1. : 0.;
88 printErr(
"super->setInputField failed with code "
89 + std::to_string(errorCode));
93 _triangTypeCode = triangulation->
getType();
94 _scalarTypeCode = scalars->GetDataType();
95 _scalarsName = scalars->GetName();
97 std::ostringstream stream;
98 stream <<
"Scalar type: " << scalars->GetDataTypeAsString() <<
" (code "
99 << _scalarTypeCode <<
")";
108 vtkUnstructuredGrid *arcs) {
111 auto points = nodes->GetPoints();
112 if(points->GetDataType() != VTK_FLOAT) {
113 printErr(
"The point coordinates must be of type float");
119 auto pData = nodes->GetPointData();
121 auto codeBuf =
getBuffer<int>(pData,
"CriticalType", VTK_INT,
"int");
122 if(!scalarBuf || !codeBuf)
128 auto cells = arcs->GetCells();
129 const auto maxNvPerC = cells->GetMaxCellSize();
132 "The points must come in pairs but there is at least one cell with "
133 + std::to_string(maxNvPerC) +
" points");
139 auto cData = arcs->GetCellData();
147 static constexpr int minCode = 0;
148 static constexpr int maxCode = 3;
149 const double sadFac = ui_extension * 0.01;
150 const double extFac = 1 - sadFac;
157 auto addPoint = [
this, coords, scalarBuf](
int p,
float isoval,
int code) {
158 const auto point = &coords[p * 3];
159 _coords.push_back(point[0]);
160 _coords.push_back(point[1]);
161 _coords.push_back(point[2]);
162 _scalars.push_back(scalarBuf[p]);
163 _isovals.push_back(isoval);
164 _flags.push_back(code == minCode ? 0 : 1);
167 const vtkIdType nc = arcs->GetNumberOfCells();
168 for(vtkIdType c = 0; c < nc; ++c) {
169 const auto p = c2p[c];
170 const auto q = c2q[c];
171 const auto pCode = codeBuf[p];
172 const auto qCode = codeBuf[q];
174 const bool pIsSad = pCode != minCode && pCode != maxCode;
175 const bool qIsSad = qCode != minCode && qCode != maxCode;
176 if(pIsSad || qIsSad) {
180 const auto ext = pIsSad ? q : p;
181 const auto sad = pIsSad ? p : q;
182 const float isoval = scalarBuf[ext] * extFac + scalarBuf[sad] * sadFac;
183 addPoint(ext, isoval, codeBuf[ext]);
185 printWrn(
"Arc " + std::to_string(c) +
" joins a minimum and a maximum");
186 const auto pVal = scalarBuf[p];
187 const auto qVal = scalarBuf[q];
188 const auto cVal = (pVal + qVal) / 2;
189 addPoint(p, pVal * extFac + cVal * sadFac, pCode);
190 addPoint(q, qVal * extFac + cVal * sadFac, qCode);
194 auto np = _scalars.size();
196 _coords.data(), _scalars.data(), _isovals.data(), _flags.data(), np);
198 printErr(
"setInputPoints failed with code " + std::to_string(errorCode));
208 switch(_scalarTypeCode) {
216 printErr(
"super->execute failed with code " + std::to_string(errorCode));
231 std::vector<int> ctypes(nc);
233 vtkIdType cinfoCounter = 0;
236 assert(nvOfCell >= 2 && nvOfCell <= 3);
237 ctypes[c] = nvOfCell == 2 ? VTK_LINE : VTK_TRIANGLE;
238 cinfoCounter += nvOfCell + 1;
245#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 6, 1)
246 cells->ImportLegacyFormat(cinfoArr);
248 cells->SetCells(nc, cinfoArr);
250 _outFld->SetCells(ctypes.data(), cells);
255 printErr(
"The API has changed! We have expected the default "
256 "coordinate type to be float");
262 coordArr->SetNumberOfComponents(3);
265 points->SetData(coordArr);
266 _outFld->SetPoints(points);
268 auto scalarArr = vtkFloatArray::New();
271 scalarArr->SetName(_scalarsName);
272 _outFld->GetPointData()->AddArray(scalarArr);
274 auto flagArr = vtkIntArray::New();
277 flagArr->SetName(
"isMax");
278 _outFld->GetPointData()->AddArray(flagArr);
284 coordArr->SetNumberOfComponents(3);
287 points->SetData(coordArr);
288 _outPts->SetPoints(points);
290 scalarArr = vtkFloatArray::New();
293 scalarArr->SetName(_scalarsName);
294 _outPts->GetPointData()->AddArray(scalarArr);
296 flagArr = vtkIntArray::New();
299 flagArr->SetName(
"isMax");
300 _outPts->GetPointData()->AddArray(flagArr);
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
TTK VTK-filter that wraps the contourAroundPoint processing package.
bool postprocess()
Assemble the output object from the results of the TTK module.
T * getBuffer(vtkFieldData *data, const std::string &varName, int typeCode, const std::string &typeName)
int RequestData(vtkInformation *request, vtkInformationVector **iVec, vtkInformationVector *oVec) override
bool preprocessPts(vtkUnstructuredGrid *nodes, vtkUnstructuredGrid *arcs)
int FillOutputPortInformation(int port, vtkInformation *info) override
bool preprocessFld(vtkDataSet *dataset)
int FillInputPortInformation(int port, vtkInformation *info) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
static void SetVoidArray(vtkDataArray *array, void *data, vtkIdType size, int save)
int setInputField(triangulationType *triangulation, void *scalars, double sizeFilter, double radius=0.)
std::vector< float > _outCentroidsCoords
std::vector< float > _outContoursScalars
std::vector< float > _outContoursCoords
std::vector< int > _outCentroidsFlags
std::vector< float > _outCentroidsScalars
std::vector< LongSimplexId > _outContoursCinfos
int setInputPoints(float *coords, float *scalars, float *isovals, int *flags, std::size_t np)
std::vector< int > _outContoursFlags
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Triangulation is a class that provides time and memory efficient traversal methods on triangulations ...
Triangulation::Type getType() const
int SimplexId
Identifier type for simplices of any dimension.
vtkStandardNewMacro(ttkContourAroundPoint)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)