1#include <vtkCellData.h>
2#include <vtkDataArray.h>
4#include <vtkInformation.h>
6#include <vtkObjectFactory.h>
7#include <vtkPointData.h>
8#include <vtkSignedCharArray.h>
9#include <vtkSmartPointer.h>
10#include <vtkUnstructuredGrid.h>
20ttkJacobiSet::ttkJacobiSet() {
21 this->SetNumberOfInputPorts(1);
22 this->SetNumberOfOutputPorts(1);
23 ForceInputOffsetScalarField =
false;
26int ttkJacobiSet::FillInputPortInformation(
int port, vtkInformation *info) {
28 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
34int ttkJacobiSet::FillOutputPortInformation(
int port, vtkInformation *info) {
35 if(port == 0 || port == 1) {
36 info->Set(vtkDataObject::DATA_TYPE_NAME(),
"vtkUnstructuredGrid");
42template <
class dataTypeU,
class dataTypeV>
43int ttkJacobiSet::dispatch(
const dataTypeU *
const uField,
44 const dataTypeV *
const vField,
48 this->execute(jacobiSet_, uField, vField,
49 *
static_cast<TTK_TT *
>(triangulation->
getData()),
54int ttkJacobiSet::RequestData(vtkInformation *
ttkNotUsed(request),
55 vtkInformationVector **inputVector,
56 vtkInformationVector *outputVector) {
58 const auto input = vtkDataSet::GetData(inputVector[0]);
59 auto output = vtkUnstructuredGrid::GetData(outputVector);
61 const auto uComponent = this->GetInputArrayToProcess(0, input);
62 const auto vComponent = this->GetInputArrayToProcess(1, input);
64 if(uComponent ==
nullptr || vComponent ==
nullptr)
67 this->
printMsg(
"U-component: `" + std::string{uComponent->GetName()} +
"'");
68 this->
printMsg(
"V-component: `" + std::string{vComponent->GetName()} +
"'");
71 if(triangulation ==
nullptr)
76 const auto offsetFieldU = this->GetOrderArray(
77 input, 0, triangulation,
false, 2, ForceInputOffsetScalarField);
78 const auto offsetFieldV = this->GetOrderArray(
79 input, 1, triangulation,
false, 3, ForceInputOffsetScalarField);
86#ifndef TTK_ENABLE_DOUBLE_TEMPLATING
87 if(uComponent->GetDataType() != vComponent->GetDataType()) {
89 "Scalar fields should have same input type. Use TTKPointDataConverter or "
90 "TTKArrayEditor to convert array types.");
93 switch(uComponent->GetDataType()) {
100 switch(vtkTemplate2PackMacro(
101 uComponent->GetDataType(), vComponent->GetDataType())) {
109 vtkNew<vtkSignedCharArray> edgeTypes{};
111 edgeTypes->SetNumberOfComponents(1);
112 edgeTypes->SetNumberOfTuples(2 * jacobiSet_.size());
113 edgeTypes->SetName(
"Critical Type");
115 vtkNew<vtkSignedCharArray> isPareto{};
116 isPareto->SetNumberOfComponents(1);
117 isPareto->SetNumberOfTuples(2 * jacobiSet_.size());
118 isPareto->SetName(
"IsPareto");
120 vtkNew<vtkPoints> pointSet{};
121 pointSet->SetNumberOfPoints(2 * jacobiSet_.size());
123 vtkNew<vtkCellArray> cellArray{};
124 vtkNew<vtkIdList> idList{};
125 idList->SetNumberOfIds(2);
127 size_t pointCount = 0;
128 std::array<double, 3> p{};
129 for(
size_t i = 0; i < jacobiSet_.size(); i++) {
131 int const edgeId = jacobiSet_[i].first;
133 triangulation->getEdgeVertex(edgeId, 0, vertexId0);
134 triangulation->getEdgeVertex(edgeId, 1, vertexId1);
136 input->GetPoint(vertexId0, p.data());
137 pointSet->SetPoint(pointCount, p.data());
138 edgeTypes->SetTuple1(pointCount, (
float)jacobiSet_[i].second);
139 isPareto->SetTuple1(pointCount, (
float)isPareto_[i]);
141 idList->SetId(0, pointCount);
144 input->GetPoint(vertexId1, p.data());
145 pointSet->SetPoint(pointCount, p.data());
146 edgeTypes->SetTuple1(pointCount, (
float)jacobiSet_[i].second);
147 isPareto->SetTuple1(pointCount, (
float)isPareto_[i]);
148 idList->SetId(1, pointCount);
151 cellArray->InsertNextCell(idList);
153 output->SetPoints(pointSet);
154 output->SetCells(VTK_LINE, cellArray);
155 output->GetPointData()->AddArray(edgeTypes);
156 output->GetPointData()->AddArray(isPareto);
159 vtkNew<ttkSimplexIdTypeArray> edgeIdArray{};
160 edgeIdArray->SetNumberOfComponents(1);
161 edgeIdArray->SetNumberOfTuples(jacobiSet_.size());
162 edgeIdArray->SetName(
"EdgeIds");
165 for(
size_t i = 0; i < jacobiSet_.size(); i++) {
166 edgeIdArray->SetTuple1(pointCount, (
float)jacobiSet_[i].first);
170 output->GetCellData()->AddArray(edgeIdArray);
172 output->GetCellData()->RemoveArray(
"EdgeIds");
177 for(
int i = 0; i < input->GetPointData()->GetNumberOfArrays(); i++) {
179 const auto scalarField = input->GetPointData()->GetArray(i);
181 scalarField->NewInstance()};
183 scalarArray->SetNumberOfComponents(scalarField->GetNumberOfComponents());
184 scalarArray->SetNumberOfTuples(2 * jacobiSet_.size());
185 scalarArray->SetName(scalarField->GetName());
186 std::vector<double> value(scalarField->GetNumberOfComponents());
188 for(
size_t j = 0; j < jacobiSet_.size(); j++) {
189 int const edgeId = jacobiSet_[j].first;
191 triangulation->getEdgeVertex(edgeId, 0, vertexId0);
192 triangulation->getEdgeVertex(edgeId, 1, vertexId1);
194 scalarField->GetTuple(vertexId0, value.data());
195 scalarArray->SetTuple(2 * j, value.data());
197 scalarField->GetTuple(vertexId1, value.data());
198 scalarArray->SetTuple(2 * j + 1, value.data());
200 output->GetPointData()->AddArray(scalarArray);
203 for(
int i = 0; i < input->GetPointData()->GetNumberOfArrays(); i++) {
204 output->GetPointData()->RemoveArray(
205 input->GetPointData()->GetArray(i)->GetName());
#define ttkTemplateMacro(triangulationType, call)
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Triangulation is a class that provides time and memory efficient traversal methods on triangulations ...
AbstractTriangulation * getData()
Triangulation::Type getType() const
void preconditionTriangulation(AbstractTriangulation &triangulation)
Triangulation precondition function.
int SimplexId
Identifier type for simplices of any dimension.
vtkStandardNewMacro(ttkJacobiSet)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)