[vtkusers] VtkPCAAnalysis

Jonathan Bailleul Jonathan.Bailleul at greyc.ismra.fr
Wed Sep 8 11:04:40 EDT 2004


Julie PELLETIER wrote:
> 
>     Hello,
> 
> I want to know how to use GetParameterisedShape from
> VtkPCAAnalysisFilter.  What to use as input and what I will get for
> output and how can I display it.
> 
> Thanks
> 
> Julie Pelletier
> 
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers


For instance:


vtkPointSet*
CreateShapeInstance(vtkPCAAnalysisFilter *pca_filter, char* filename, 
		    int mode, float variance_fact, vtkPointSet *shape_container)
{
  vtkFloatArray *params = vtkFloatArray::New();
  params -> SetNumberOfComponents(1); // 1 per tuple
  params -> SetNumberOfTuples(1 + mode); // 1 instance 


  // float val[1]; val[0] = variance_fact; params -> SetTuple(0, val);
  for (int i = 0; i < mode; i++) {params -> SetTuple1(i, 0.0);}
  params -> SetTuple1(mode, variance_fact);
  
  pca_filter -> GetParameterisedShape(params, shape_container);

  if (filename != NULL)
    {
      vtkDataSetWriter *writer = vtkDataSetWriter::New();
      
      writer -> SetFileName(filename);
      writer -> SetInput(shape_container);
      writer -> Update();
    }

  return shape_container;
}


vtkPointSet*
CreateShapeInstance(vtkPCAAnalysisFilter *pca_filter, int nb_modes,
float* mode_b,
		    vtkPointSet *shape_container)
{
  vtkFloatArray *params = vtkFloatArray::New();
  params -> SetArray(mode_b, nb_modes, 1);

  pca_filter -> GetParameterisedShape(params, shape_container);

  return shape_container;
}


vtkPointSet*
CreateShapeInstance(vtkPCAAnalysisFilter *pca_filter, int nb_modes,
vtkFloatArray* mode_b,
		    vtkPointSet *shape_container)
{
  vtkFloatArray *params = vtkFloatArray::New(); 
  params -> SetNumberOfComponents(1); // 1 per tuple
  params -> SetNumberOfTuples(nb_modes); // 1 instance 
  for (int i = 0; i < nb_modes; i++) 
    params -> SetComponent(i, 0, mode_b -> GetComponent(i, 0));

  pca_filter -> GetParameterisedShape(params, shape_container);

  return shape_container;
}


If the input points come from a polydata, you can save the output in
polydata, that will keep the same connectivity (not always a good idea).
In that case, you can just visualize the polydata in a standard way! I
know more clever tools have been developped, but I didn't manage to get
a hand on these.
If you just have unordered points, then maybe consider Delaunay (I'm
interested in tips on that field).

Best regards,

-- 
-----------------------------------
Jonathan BAILLEUL, Doctorant
GREYC Image - Université de Caen 
http://www.greyc.ismra.fr/~bailleul




More information about the vtkusers mailing list