This old site has described an import/export method, but I suspect there must be an easier generic way of handling this common task in libvtk. As the initial texture/map is not being modified, it makes sense someone likely encountered this performance constraint already at some point.
I am trying to tile planes created by clipping an obj file, extract the texture mapped edge color/alpha information, and create a mine-craft style voxel world (similar method to vtkMarchingSquares).
As the memory requirement balloons rather quickly, I am planning to only keep 3 planes resident while decomposing the 3D obj into a smaller set of colored glyphs.
My current horrible design will apply vtkImageHistogram to the rendered camera/light angles perpendicular to each face in the 3D region of interest (cut surfaces are filled with black polygons), and use the dominant RGB histograms to down-sample the texture information.
This is not going to win any speed or beauty contests, but should work for my toy project.
Cheers,
J
Examples I am currently looking at:
TextureCutSphere
ClipClosedSurface
ClipFrustum
The following does not work as expected, and is based on the ClipClosedSurface Example:
`
vtkActor* actor = actors->GetNextActor(); //parsing obj actors with textures
vtkPolyData* polyDataTmp = dynamic_cast<vtkPolyData*>(actor->GetMapper()->GetInput());
auto localCenter = polyDataTmp->GetCenter();
vtkNew<vtkPlane> planeClip1;
planeClip1->SetOrigin(localCenter[COORDS_X], localCenter[COORDS_Y], localCenter[COORDS_Z]);
planeClip1->SetNormal(0.0, -1.0, 0.0);
vtkNew<vtkPlane> planeClip2;
planeClip2->SetOrigin(localCenter[COORDS_X], localCenter[COORDS_Y], localCenter[COORDS_Z]);
planeClip2->SetNormal(0.0, 0.0, 1.0);
vtkNew<vtkPlane> planeClip3;
planeClip3->SetOrigin(localCenter[COORDS_X], localCenter[COORDS_Y], localCenter[COORDS_Z]);
planeClip3->SetNormal(-1.0, 0.0, 0.0);
vtkNew<vtkPlaneCollection> planeClips;
planeClips->AddItem(planeClip1);
planeClips->AddItem(planeClip2);
planeClips->AddItem(planeClip3);
vtkNew<vtkClipClosedSurface> clipper;
clipper->SetInputData(polyDataTmp);
clipper->SetClippingPlanes(planeClips);
clipper->SetActivePlaneId(2);
clipper->SetScalarModeToColors();
//clipper->SetClipColor(colors->GetColor3d("Banana").GetData());
//clipper->SetBaseColor(colors->GetColor3d("Tomato").GetData());
//clipper->SetActivePlaneColor(colors->GetColor3d("Blue").GetData());
vtkNew<vtkDataSetMapper> clipMapper;
clipMapper->SetInputConnection(clipper->GetOutputPort());
vtkNew<vtkActor> clipActor;
clipActor->SetMapper(clipMapper);
clipActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
clipActor->GetProperty()->SetInterpolationToFlat();
vtkSmartPointer<vtkTexture> texture = actor->GetTexture(); //todo: fix shallow copy of vtkTexture obj
clipActor->SetTexture(texture);
renderer->AddActor(clipActor);
//no display of texture on new mesh slice
`