Skip to content
Snippets Groups Projects
Verified Commit 249a4a0e authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri :speech_balloon:
Browse files

Ghost arrays support in vtkExtractSelection

New boolean parameter controls whether to ignore masked points/cells
from pass through to the output. The default behavior of the class
remains unchanged.
parent 3036e193
No related branches found
No related tags found
No related merge requests found
# Ghost arrays in vtkExtractSelection
A new flag `TestGhostArrays` is added to `vtkExtractSelection` that when enabled, asks the
extraction filter to skip hidden points/cells from passing through to the output. By default, this
flag is `false` and the default behavior of the class remains the same.
......@@ -935,8 +935,16 @@ void vtkExtractSelection::ExtractSelectedCells(
// convert insideness array to cell ids to extract.
vtkNew<vtkIdList> ids;
ids->Allocate(numCells);
vtkDataArray* ghostArray = nullptr;
ghostArray = input->GetCellGhostArray();
for (vtkIdType cc = 0; cc < numCells; ++cc)
{
if (this->TestGhostArrays &&
ghostArray->GetVariantValue(cc) == vtkDataSetAttributes::HIDDENCELL)
{
// skip this cell
continue;
}
if (cellInside->GetValue(cc) != 0)
{
ids->InsertNextId(cc);
......@@ -981,8 +989,16 @@ void vtkExtractSelection::ExtractSelectedPoints(
}
vtkNew<vtkIdList> ids;
ids->Allocate(numPts);
vtkDataArray* ghostArray = nullptr;
ghostArray = input->GetPointGhostArray();
for (vtkIdType cc = 0; cc < numPts; ++cc)
{
if (this->TestGhostArrays &&
ghostArray->GetVariantValue(cc) == vtkDataSetAttributes::HIDDENPOINT)
{
// skip this point
continue;
}
if (pointInside->GetValue(cc) != 0)
{
ids->InsertNextId(cc);
......
......@@ -77,6 +77,19 @@ public:
vtkBooleanMacro(HyperTreeGridToUnstructuredGrid, bool);
///@}
///@{
/**
* This flag controls whether the extraction filter tests for ghost arrays in the input dataset.
* When enabled, points/cells masked using ghost arrays are ignored from the extraction step and
* do not pass through to the output.
*
* Default is set to false
*/
vtkGetMacro(TestGhostArrays, bool);
vtkSetMacro(TestGhostArrays, bool);
vtkBooleanMacro(TestGhostArrays, bool);
///@}
protected:
vtkExtractSelection();
~vtkExtractSelection() override;
......@@ -171,6 +184,7 @@ protected:
vtkTable* input, vtkTable* output, vtkSignedCharArray* rowsInside, bool extractAll);
bool PreserveTopology = false;
bool TestGhostArrays = false;
private:
vtkExtractSelection(const vtkExtractSelection&) = delete;
......
vtk_add_test_cxx(vtkFiltersFlowPathsCxxTests tests
TestBSPTree.cxx
TestBSPTreeWithGhostArrays.cxx
TestCellLocatorsLinearTransform.cxx,NO_DATA,NO_VALID,NO_OUTPUT
TestEvenlySpacedStreamlines2D.cxx
TestStreamTracer.cxx,NO_VALID
......
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
* Description
* Test ray intersection of polygons using vtkModifiedBSPTree locator and subsequent extraction of
* selected cells for a dataset containing ghost arrays
*/
#include "vtkActor.h"
#include "vtkBoundingBox.h"
#include "vtkCamera.h"
#include "vtkDataSetAttributes.h"
#include "vtkDataSetMapper.h"
#include "vtkExtractSelection.h"
#include "vtkGlyph3DMapper.h"
#include "vtkLineSource.h"
#include "vtkModifiedBSPTree.h"
#include "vtkNew.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSelectionSource.h"
#include "vtkSphereSource.h"
#include "vtkTesting.h"
#include "vtkUnstructuredGrid.h"
int TestBSPTreeWithGhostArrays(int argc, char* argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
vtkNew<vtkRenderWindow> renWin;
renWin->SetMultiSamples(0);
renWin->SetSize(301, 300); // Intentional NPOT size
vtkNew<vtkRenderer> renderer;
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetRadius(0.05);
sphereSource->Update();
vtkSmartPointer<vtkPolyData> sphere = sphereSource->GetOutput();
sphere->AllocateCellGhostArray();
vtkSmartPointer<vtkUnsignedCharArray> ghostCells = sphere->GetCellGhostArray();
ghostCells->SetTuple1(72, vtkDataSetAttributes::HIDDENCELL);
ghostCells->SetTuple1(19, vtkDataSetAttributes::HIDDENCELL);
double bounds[6];
sphere->GetBounds(bounds);
vtkBoundingBox box(bounds);
double tol = box.GetDiagonalLength() / 1E6;
vtkNew<vtkModifiedBSPTree> bspTree;
bspTree->SetDataSet(sphere);
bspTree->SetMaxLevel(12);
bspTree->SetNumberOfCellsPerNode(16);
bspTree->BuildLocator();
// Render BSP tree
vtkNew<vtkPolyData> bspPD;
bspTree->GenerateRepresentation(2, bspPD);
vtkNew<vtkPolyDataMapper> bspMapper;
bspMapper->SetInputData(bspPD);
vtkNew<vtkActor> bspAc;
bspAc->SetMapper(bspMapper);
bspAc->GetProperty()->SetInterpolationToFlat();
bspAc->GetProperty()->SetOpacity(.3);
bspAc->GetProperty()->EdgeVisibilityOn();
bspAc->GetProperty()->SetColor(0.45, 0.25, 0.6);
renderer->AddActor(bspAc);
//
// Intersect Ray with BSP tree full of spheres
//
vtkNew<vtkPoints> verts;
vtkNew<vtkIdList> cellIds;
double p1[3] = { -0.1, -0.1, -0.1 };
double p2[3] = { 0.1, 0.1, 0.1 };
bspTree->IntersectWithLine(p1, p2, tol, verts, cellIds);
vtkNew<vtkPolyData> intersections;
vtkNew<vtkCellArray> vertices;
vtkIdType n = verts->GetNumberOfPoints();
for (vtkIdType i = 0; i < n; i++)
{
vertices->InsertNextCell(1, &i);
}
intersections->SetPoints(verts);
intersections->SetVerts(vertices);
std::cout << "Number of intersections is " << n << std::endl;
vtkNew<vtkSelectionSource> selection;
vtkNew<vtkExtractSelection> extract;
selection->SetContentType(vtkSelectionNode::INDICES);
selection->SetFieldType(vtkSelectionNode::CELL);
for (int i = 0; i < cellIds->GetNumberOfIds(); i++)
{
std::cout << cellIds->GetId(i) << ",";
selection->AddID(-1, cellIds->GetId(i));
}
std::cout << std::endl;
//
extract->SetInputData(sphere);
extract->SetSelectionConnection(selection->GetOutputPort());
extract->TestGhostArraysOn(); // Remove hidden points/cells from extraction
extract->Update();
vtkSmartPointer<vtkUnstructuredGrid> extractedCells =
vtkUnstructuredGrid::SafeDownCast(extract->GetOutputDataObject(0));
if (!extractedCells || extractedCells->GetNumberOfCells() != 2)
{
return EXIT_FAILURE;
}
//
// Render cloud of target spheres
//
vtkNew<vtkPolyDataMapper> smapper;
smapper->SetInputData(sphere);
vtkNew<vtkProperty> sproperty;
sproperty->SetColor(1.0, 1.0, 1.0);
// sproperty->SetOpacity(0.25);
sproperty->SetAmbient(0.0);
sproperty->SetBackfaceCulling(1);
sproperty->SetFrontfaceCulling(0);
sproperty->SetRepresentationToPoints();
// sproperty->SetInterpolationToFlat();
vtkNew<vtkActor> sactor;
sactor->SetMapper(smapper);
sactor->SetProperty(sproperty);
renderer->AddActor(sactor);
//
// Render Intersection points
//
vtkNew<vtkGlyph3DMapper> imapper;
imapper->SetInputData(intersections);
imapper->SetSourceConnection(sphereSource->GetOutputPort());
imapper->SetScaleFactor(0.05);
vtkNew<vtkProperty> iproperty;
iproperty->SetOpacity(1.0);
iproperty->SetColor(0.0, 0.0, 1.0);
iproperty->SetBackfaceCulling(1);
iproperty->SetFrontfaceCulling(0);
vtkNew<vtkActor> iactor;
iactor->SetMapper(imapper);
iactor->SetProperty(iproperty);
renderer->AddActor(iactor);
//
// Render Ray
//
vtkNew<vtkLineSource> ray;
ray->SetPoint1(p1);
ray->SetPoint2(p2);
vtkNew<vtkPolyDataMapper> rmapper;
rmapper->SetInputConnection(ray->GetOutputPort(0));
vtkNew<vtkActor> lactor;
lactor->SetMapper(rmapper);
renderer->AddActor(lactor);
//
// Render Intersected Cells (extracted using selection)
//
vtkNew<vtkDataSetMapper> cmapper;
cmapper->SetInputConnection(extract->GetOutputPort(0));
vtkNew<vtkProperty> cproperty;
cproperty->SetColor(0.0, 1.0, 1.0);
cproperty->SetBackfaceCulling(0);
cproperty->SetFrontfaceCulling(0);
cproperty->SetAmbient(1.0);
cproperty->SetLineWidth(3.0);
cproperty->SetRepresentationToWireframe();
cproperty->SetInterpolationToFlat();
vtkNew<vtkActor> cactor;
cactor->SetMapper(cmapper);
cactor->SetProperty(cproperty);
renderer->AddActor(cactor);
//
// Standard testing code.
//
renWin->SetSize(300, 300);
renWin->SetMultiSamples(0);
renWin->Render();
renderer->GetActiveCamera()->SetPosition(0.0, 0.15, 0.0);
renderer->GetActiveCamera()->SetFocalPoint(0.0, 0.0, 0.0);
renderer->GetActiveCamera()->SetViewUp(0.0, 0.0, 1.0);
renderer->SetBackground(0.0, 0.0, 0.0);
renderer->ResetCamera();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
1a68ef7ca923546cdc550121fb0a30ed55289011cad970ddc8ae832ed8cb6f719b0a36ab55d633e63abe731ef886f76f71fc966c73d572bcaa41e1ecd363ba03
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment