3#include <vtkDataObject.h>
4#include <vtkObjectFactory.h>
6#include <vtkCellData.h>
8#include <vtkDataArray.h>
10#include <vtkInformation.h>
11#include <vtkIntArray.h>
12#include <vtkPointData.h>
13#include <vtkPointSet.h>
14#include <vtkSmartPointer.h>
19#include <vtkUnstructuredGrid.h>
25 this->SetNumberOfInputPorts(1);
26 this->SetNumberOfOutputPorts(1);
30 this->ArraySelection->AddObserver(
31 vtkCommand::ModifiedEvent,
this, &ttkTriangulationManager::Modified);
33 hasMPISupport_ =
true;
38 vtkInformation *info) {
40 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
47 vtkInformation *info) {
56 vtkInformation *request,
57 vtkInformationVector **inputVector,
58 vtkInformationVector *outputVector) {
59 if(Periodicity && ttk::isRunningWithMPI()) {
60 return this->periodicGhostGenerator->RequestUpdateExtent(
61 request, inputVector, outputVector);
66 vtkInformation *request,
67 vtkInformationVector **inputVectors,
68 vtkInformationVector *outputVector) {
69 if(Periodicity && ttk::isRunningWithMPI()) {
70 return this->periodicGhostGenerator->RequestInformation(
71 request, inputVectors, outputVector);
83 vtkImageData *imageIn,
84 vtkImageData *imageOut,
92 if(prevPeriodic != periodic) {
95 if(ttk::isRunningWithMPI()) {
96 periodicGhostGenerator->MPIPeriodicGhostPipelinePreconditioning(
98 triangulation.setIsMPIValid(
false);
100 debugLevel, cacheSize, imageOut);
101 newTriangulation->setPeriodicBoundaryConditions(periodic);
103 std::vector<int> &neighbors = newTriangulation->getNeighborRanks();
104 std::map<int, int> &neighborsToId
105 = newTriangulation->getNeighborsToId();
106 neighbors = periodicGhostGenerator->getNeighbors();
107 neighborsToId = periodicGhostGenerator->getNeighborsToId();
108 newTriangulation->setIsBoundaryPeriodic(
109 periodicGhostGenerator->getIsBoundaryPeriodic());
114 dbg.printMsg(
"Switching regular grid periodicity from "
115 + (prevPeriodic ? std::string(
"ON") : std::string(
"OFF"))
117 + (periodic ? std::string(
"ON") : std::string(
"OFF")));
126 && !prevPreconditions)
128 && prevPreconditions)) {
134 if(prevPreconditions != newPreconditions) {
135 dbg.
printMsg(
"Switching regular grid preconditions from "
136 + (prevPreconditions ? std::string(
"ON") : std::string(
"OFF"))
138 + (newPreconditions ? std::string(
"ON") : std::string(
"OFF")));
145 vtkImageData *imageIn,
146 vtkImageData *imageOut
150 switchPeriodicity(triangulation, this->Periodicity, *
this
153 imageIn, imageOut, this->periodicGhostGenerator,
157 switchPreconditions(triangulation, this->PreconditioningStrategy, *
this);
161 vtkUnstructuredGrid *
const output,
162 vtkPointSet *
const input,
165 if(output ==
nullptr || input ==
nullptr) {
172 if((ttk::hasInitializedMPI()) && (ttk::isRunningWithMPI())) {
173 this->
printWrn(
"Compact triangulation not supported with MPI!");
174 this->
printWrn(
"Keeping the Explicit triangulation.");
175 output->ShallowCopy(input);
181 this->
printMsg(
"Compact explicit triangulation...");
186 (status = worker.execute(
187 static_cast<TTK_TT *
>(triangulation.
getData()), this->Threshold)));
194 std::vector<vtkDataArray *> pointDataArrays{};
195 std::vector<vtkDataArray *> cellDataArrays{};
197 vtkPointData *inPointData = input->GetPointData();
198 for(
int i = 0; i < inPointData->GetNumberOfArrays(); i++) {
199 vtkDataArray *curArray = inPointData->GetArray(i);
200 if(curArray !=
nullptr && curArray->GetName() !=
nullptr
201 && ArraySelection->ArrayIsEnabled(curArray->GetName())) {
202 pointDataArrays.emplace_back(curArray);
206 vtkCellData *inCellData = input->GetCellData();
207 for(
int i = 0; i < inCellData->GetNumberOfArrays(); i++) {
208 vtkDataArray *curArray = inCellData->GetArray(i);
209 if(curArray !=
nullptr && curArray->GetName() !=
nullptr
210 && ArraySelection->ArrayIsEnabled(curArray->GetName())) {
211 cellDataArrays.emplace_back(curArray);
215 output->Initialize();
217 const auto &vertices{worker.getVertices()};
218 const auto &nodes{worker.getNodes()};
219 const auto &cells{worker.getCells()};
220 std::vector<ttk::SimplexId> vertexMap(vertices.size());
222 vtkNew<vtkPoints> points{};
223 vtkNew<vtkIntArray> indices{};
225 indices->SetNumberOfComponents(1);
229 for(
size_t i = 0; i < vertices.size(); i++) {
232 points->InsertNextPoint(x, y, z);
233 vertexMap[vertices[i]] = i;
234 indices->InsertNextTuple1(nodes[i]);
236 output->SetPoints(points);
238 output->GetPointData()->AddArray(indices);
241 output->Allocate(cells.size());
243 if(dimension > 4 || dimension < 2) {
244 this->
printErr(
"Dimension not supported");
248 for(
unsigned int i = 0; i < cells.size(); i++) {
249 std::array<vtkIdType, 4> cell{};
250 for(
size_t j = 0; j < dimension; j++) {
253 cell[j] = vertexMap[vertexId];
255 std::sort(cell.begin(), cell.begin() + dimension);
257 output->InsertNextCell(VTK_LINE, 2, cell.data());
258 }
else if(dimension == 3) {
259 output->InsertNextCell(VTK_TRIANGLE, 3, cell.data());
260 }
else if(dimension == 4) {
261 output->InsertNextCell(VTK_TETRA, 4, cell.data());
263 this->
printErr(
"Should not get here!");
268 for(vtkDataArray *scalarArray : pointDataArrays) {
270 scalarArray->NewInstance());
271 updatedField->SetName(scalarArray->GetName());
272 for(
size_t j = 0; j < vertices.size(); j++) {
273 updatedField->InsertTuple(j, scalarArray->GetTuple(vertices[j]));
276 output->GetPointData()->AddArray(updatedField);
280 for(vtkDataArray *scalarArray : cellDataArrays) {
282 scalarArray->NewInstance());
283 updatedField->SetName(scalarArray->GetName());
284 for(
size_t j = 0; j < cells.size(); j++) {
285 updatedField->InsertTuple(j, scalarArray->GetTuple(cells[j]));
288 output->GetCellData()->AddArray(updatedField);
291 this->
printMsg(
"Done!", 1.0, tm.getElapsedTime(), 1);
298 vtkInformationVector **inputVector,
299 vtkInformationVector *outputVector) {
301 auto *inputDataSet = vtkDataSet::GetData(inputVector[0]);
304 if(triangulation ==
nullptr) {
305 this->
printErr(
"Triangulation is NULL");
309 if(inputDataSet->IsA(
"vtkImageData")) {
311 vtkImageData *imageIn = vtkImageData::GetData(inputVector[0]);
312 vtkImageData *imageOut = vtkImageData::GetData(outputVector);
313 imageOut->ShallowCopy(imageIn);
317 auto *outputDataSet = vtkDataSet::GetData(outputVector, 0);
318 outputDataSet->ShallowCopy(inputDataSet);
321 }
else if(inputDataSet->IsA(
"vtkUnstructuredGrid")
322 || inputDataSet->IsA(
"vtkPolyData")) {
323 return this->
processExplicit(vtkUnstructuredGrid::GetData(outputVector, 0),
324 vtkPointSet::SafeDownCast(inputDataSet),
#define ttkTemplateMacro(triangulationType, call)
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
float CompactTriangulationCacheSize
virtual int RequestInformation(vtkInformation *ttkNotUsed(request), vtkInformationVector **ttkNotUsed(inputVectors), vtkInformationVector *ttkNotUsed(outputVector))
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
virtual int RequestUpdateExtent(vtkInformation *ttkNotUsed(request), vtkInformationVector **ttkNotUsed(inputVectors), vtkInformationVector *ttkNotUsed(outputVector))
TTK VTK-filter that generates an outside ghost layer for periodic implicit grids when used in a distr...
static ttk::Triangulation * GetTriangulation(int debugLevel, float cacheRatio, vtkDataSet *object)
TTK VTK-filter that manages ttk::Triangulation options.
void processImplicit(ttk::Triangulation &triangulation)
ttkTriangulationManager()
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int processExplicit(vtkUnstructuredGrid *const output, vtkPointSet *const input, ttk::Triangulation &triangulation) const
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
bool hasPeriodicBoundaries() const
Returns true if the grid uses period boundary conditions.
TTK processing package for mesh preprocessing before using TopoCluster.
Minimalist debugging class.
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
void setDebugMsgPrefix(const std::string &prefix)
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) 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 ...
AbstractTriangulation * getData()
bool hasImplicitPreconditions() const
Returns true if the grid uses preconditions.
Triangulation::Type getType() const
int getCellVertex(const SimplexId &cellId, const int &localVertexId, SimplexId &vertexId) const override
SimplexId getCellVertexNumber(const SimplexId &cellId) const override
int getVertexPoint(const SimplexId &vertexId, float &x, float &y, float &z) const override
void setPeriodicBoundaryConditions(const bool &usePeriodicBoundaries)
void setImplicitPreconditions(const STRATEGY strategy)
Set the input grid preconditioning strategy.
const char compactTriangulationIndex[]
int SimplexId
Identifier type for simplices of any dimension.
vtkStandardNewMacro(ttkTriangulationManager)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)