[vtkusers] Java vtkPointToCellData
James Labiak
jim at jslengineeringsoftware.com
Mon Sep 21 21:05:16 EDT 2015
Hi Sebastien,
I made the change, but it still seems not to be running the filter.
Attached is a java file and a .vtp data file to see what's happening.
Also below is the code.
Thanks,
Jim
package com.profiles;
import vtk.*;
public class PlotSomePolyDataFromFileRead {
public static void main(String[] args) {
try {
new PlotSomePolyDataFromFileRead();
} catch (Exception ex_new_PlotSomePolyDataFromFileRead) {
System.out.println("[main] Exception at new
PlotSomePolyDataFromFileRead()");
ex_new_PlotSomePolyDataFromFileRead.printStackTrace();
}
}
// Load VTK libraries
static {
if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
{
for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if (!lib.IsLoaded())
System.out
.println(lib.GetLibraryName() + " not
loaded");
}
System.out.println("Make sure the search path is
correct: ");
System.out.println(System.getProperty("java.library.path"));
}
vtkNativeLibrary.DisableOutputWindow(null);
}
}
private PlotSomePolyDataFromFileRead() {
// Read the polyData from the data file
vtkXMLPolyDataReader xmlReader = new vtkXMLPolyDataReader();
xmlReader.SetFileName("C:\\vtk123\\test_data.vtp");
xmlReader.Update();
// Use the filter vtkPointDataToCellData to create the
// cells from the point data that's in the vtkPolyData from the
reader
// *The vtkPolyData from the reader intentionally only includes
vtkPoints
// and their scalars (that's the given data from the
application output)
vtkPointDataToCellData polyDataCreateCells = new
vtkPointDataToCellData();
polyDataCreateCells.SetInputConnection(xmlReader.GetOutputPort());
polyDataCreateCells.PassPointDataOn();
polyDataCreateCells.Update();
// In order to check if the vtkPointDataToCellData filter worked:
// Create new polyData, retrieve polyData (with cells now) from
// polyDataCreateCells filter, check values during debug operation
vtkPolyData polyDataWithCells = new vtkPolyData();
polyDataWithCells = polyDataCreateCells.GetPolyDataOutput();
// At this point, polyDataWithCells has (when I run it)
// point data but not cell data, nor scalar data
// and it should have all 3
vtkPolyDataMapper polyMapper = new vtkPolyDataMapper();
polyMapper.SetInputData(polyDataCreateCells.GetPolyDataOutput());
polyMapper.Update();
vtkActor polyActor = new vtkActor();
polyActor.SetMapper(polyMapper);
polyActor.GetProperty().SetColor(1.0, 1.0, 1.0);
vtkRenderer renderer = new vtkRenderer();
renderer.AddActor(polyActor);
renderer.SetBackground(0.0, 0.0, 0.0);
vtkRenderWindow renderWindow = new vtkRenderWindow();
renderWindow.AddRenderer(renderer);
renderWindow.SetSize(800, 800);
vtkRenderWindowInteractor renderWindowInteractor = new
vtkRenderWindowInteractor();
renderWindowInteractor.SetRenderWindow(renderWindow);
renderWindow.Render();
renderWindowInteractor.Start();
}
}
On 9/21/2015 10:38 AM, Sebastien Jourdain wrote:
> Try that
>
> vtkPointDataToCellData polyDataCreateCells = new vtkPointDataToCellData();
> polyDataCreateCells.SetInputData(polyData);
> polyDataCreateCells.PassPointDataOn();
> polyDataCreateCells.Update(); // <==== For the execution of the filter
>
> // Create new polyData, retrieve completed polyData from
> polyDataCreateCells
> vtkPolyData polyDataComplete =
> polyDataCreateCells.GetPolyDataOutput(); // No need to create a
> polydata just get a ref from the filter
>
> On Mon, Sep 21, 2015 at 8:20 AM, James Labiak
> <jim at jslengineeringsoftware.com
> <mailto:jim at jslengineeringsoftware.com>> wrote:
>
> Hello all,
> I created a pipeline that seems to make sense to me, but always my
> polyDataComplete is empty. Any ideas why this code doesn't work?
> The only vtkPointToCellData example on the web that I can find
> uses blow.vtk, which doesn't exist on my 6.0.0 installation
> anywhere. The polyData variable gets correctly populated with the
> points and their scalars below.
>
> // Create a new, empty polyData
> polyData = new vtkPolyData();
>
> // populate the polyData points
> polyData.SetPoints(points);
>
> // populate the polyData scalars
> polyData.GetPointData().SetScalars(colorsScalars);
>
> vtkPointDataToCellData polyDataCreateCells = new
> vtkPointDataToCellData();
> polyDataCreateCells.SetInputData(polyData);
> polyDataCreateCells.PassPointDataOn();
>
> // Create new polyData, retrieve completed polyData from
> polyDataCreateCells
> vtkPolyData polyDataComplete = new vtkPolyData();
> polyDataComplete = polyDataCreateCells.GetPolyDataOutput();
>
> vtkPolyDataMapper polyMapper = new vtkPolyDataMapper();
> polyMapper.SetInputData(polyDataComplete);
> polyMapper.ScalarVisibilityOn();
> polyMapper.SetScalarRange(scalarMin, scalarMax);
> polyMapper.Update();
>
> vtkActor polyActor = new vtkActor();
> polyActor.SetMapper(polyMapper);
> polyActor.GetProperty().SetColor(1.0, 1.0, 1.0);
>
> // ...Usual render stuff...
>
> Thanks,
> Jim
>
> _______________________________________________
> Powered by www.kitware.com <http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150921/86226747/attachment.html>
-------------- next part --------------
package com.profiles;
import vtk.*;
public class PlotSomePolyDataFromFileRead {
public static void main(String[] args) {
try {
new PlotSomePolyDataFromFileRead();
} catch (Exception ex_new_PlotSomePolyDataFromFileRead) {
System.out.println("[main] Exception at new PlotSomePolyDataFromFileRead()");
ex_new_PlotSomePolyDataFromFileRead.printStackTrace();
}
}
// Load VTK libraries
static {
if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
{
for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if (!lib.IsLoaded())
System.out
.println(lib.GetLibraryName() + " not loaded");
}
System.out.println("Make sure the search path is correct: ");
System.out.println(System.getProperty("java.library.path"));
}
vtkNativeLibrary.DisableOutputWindow(null);
}
}
private PlotSomePolyDataFromFileRead() {
// Read the polyData from the data file
vtkXMLPolyDataReader xmlReader = new vtkXMLPolyDataReader();
xmlReader.SetFileName("C:\\vtk123\\test_data.vtp");
xmlReader.Update();
// Use the filter vtkPointDataToCellData to create the
// cells from the point data that's in the vtkPolyData from the reader
// *The vtkPolyData from the reader intentionally only includes vtkPoints
// and their scalars (that's the given data from the application output)
vtkPointDataToCellData polyDataCreateCells = new vtkPointDataToCellData();
polyDataCreateCells.SetInputConnection(xmlReader.GetOutputPort());
polyDataCreateCells.PassPointDataOn();
polyDataCreateCells.Update();
// In order to check if the vtkPointDataToCellData filter worked:
// Create new polyData, retrieve polyData (with cells now) from
// polyDataCreateCells filter, check values during debug operation
vtkPolyData polyDataWithCells = new vtkPolyData();
polyDataWithCells = polyDataCreateCells.GetPolyDataOutput();
// At this point, polyDataWithCells has (when I run it)
// point data but not cell data, nor scalar data
// and it should have all 3
vtkPolyDataMapper polyMapper = new vtkPolyDataMapper();
polyMapper.SetInputData(polyDataCreateCells.GetPolyDataOutput());
polyMapper.Update();
vtkActor polyActor = new vtkActor();
polyActor.SetMapper(polyMapper);
polyActor.GetProperty().SetColor(1.0, 1.0, 1.0);
vtkRenderer renderer = new vtkRenderer();
renderer.AddActor(polyActor);
renderer.SetBackground(0.0, 0.0, 0.0);
vtkRenderWindow renderWindow = new vtkRenderWindow();
renderWindow.AddRenderer(renderer);
renderWindow.SetSize(800, 800);
vtkRenderWindowInteractor renderWindowInteractor = new vtkRenderWindowInteractor();
renderWindowInteractor.SetRenderWindow(renderWindow);
renderWindow.Render();
renderWindowInteractor.Start();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_data.vtp
Type: text/xml
Size: 15824 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150921/86226747/attachment.xml>
More information about the vtkusers
mailing list