[vtkusers] How to retrieve individual value from a vtkTable in Java

Jeff Baumes jeff.baumes at kitware.com
Tue Jan 2 09:52:31 EST 2018


vtkTable's GetRow method returns a vtkVariantArray (
https://www.vtk.org/doc/nightly/html/classvtkTable.html) which may be what
is causing trouble. This is necessary because though columns have a single
type, rows cut across columns so must be variant arrays. Perhaps try
GetColumn() instead, which you may have better luck using as a standard
array?

On Fri, Dec 22, 2017 at 9:02 AM Jean-Max Redonnet <jmax.red at gmail.com>
wrote:

> Hi,
>
> I did a K-Means clustering following the C++ example (
> https://lorensen.github.io/VTKExamples/site/Cxx/InfoVis/KMeansClustering/
> ).
>
>         vtkTable kmeansInputData = new vtkTable();
>         kmeansInputData.AddColumn(output.GetPointData().GetVectors()); //
> output object is a polydata with vectors attached resulting from previous
> calculation
>
>         vtkKMeansStatistics kMeansStatistics = new vtkKMeansStatistics();
>         kMeansStatistics.SetInputData(kmeansInputData);
>         kMeansStatistics.SetColumnStatus(kmeansInputData.GetColumnName(0),
> 1);
>         kMeansStatistics.SetColumnStatus(kmeansInputData.GetColumnName(1),
> 1);
>         kMeansStatistics.SetColumnStatus(kmeansInputData.GetColumnName(2),
> 1);
>         // kMeansStatistics.SetColumnStatus( "Testing", 1 );
>         kMeansStatistics.RequestSelectedColumns();
>         kMeansStatistics.SetAssessOption(true);
>         kMeansStatistics.SetDefaultNumberOfClusters(3);
>         kMeansStatistics.Update();
>
>         kMeansStatistics.GetOutput().Dump(32, -1); // dump shows the
> clustering is OK
>
>         vtkIntArray clusterArray = new vtkIntArray();
>         clusterArray.SetNumberOfComponents(1);
>         clusterArray.SetName("ClusterId");
>
>         for(int r = 0; r < kMeansStatistics.GetOutput().GetNumberOfRows();
> r++){
>          // at this point the C++ instruction to retrieve information is
>          // vtkVariant v = kMeansStatistics->GetOutput()->GetValue(r,
> kMeansStatistics->GetOutput()->GetNumberOfColumns() - 1);
>          // ...
>         }
>
> AFAIK vtkVariant does not exists in Java. I tried to get row first using
>           vtkAbstractArray a = kMeansStatistics.GetOutput().GetRow(r);
> My debugger indicates array a is instance of vtkFloatArray, but java cast
> doesn't work, thus I can't retrieve the value
> I guess SafeDownCast is the good method to do that, but can't find it in
> java wrapper.
>
> So, I can't figure out the right way to retrieve individual value from a
> vtkTable in Java.
>
> Any help would be really appreciated
>
> jMax
>
>
>
> _______________________________________________
> Powered by 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:
> https://vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180102/8615f5d9/attachment.html>


More information about the vtkusers mailing list