[vtkusers] about vtkPCAAnalysisFilter in vtk 6.1.0

Waldo Valenzuela waldo.valenzuela at hotmail.com
Tue Apr 15 10:19:02 EDT 2014


Hi Bill,

I had some error with the input data need it, and I did some changes and is working, but now I have to analyse if the result are correct, my new implementation is:



	// do PCA
	vtkSmartPointer<vtkPCAAnalysisFilter> pca;
	pca = vtkSmartPointer<vtkPCAAnalysisFilter>::New();
#if VTK_MAJOR_VERSION <= 5
    pca->SetNumberOfInputs( numberOfShapeVariations );
#else
	VTKMultiBlockDataSet mb = VTKMultiBlockDataSet::New();
#endif
	// setting the input data.
	for (int i = 0; i < numberOfShapeVariations; i++){
#if VTK_MAJOR_VERSION <= 5
        pca->SetInput(i,shapeVariations[i]);
#else
        mb->SetBlock(i, shapeVariations[i]);
#endif
	}
#if VTK_MAJOR_VERSION > 5
	pca->SetInputData(mb);
#endif
	std::cout<<"Start PCA"<<std::endl;
	pca->Update();
	std::cout<<"Finished PCA"<<std::endl;
    
    
	numberOfModes = shapeVariations.size();
	
	//setEigenValues
	
	eigenValues.clear();
    
	vtkSmartPointer<vtkFloatArray> evals = vtkSmartPointer<vtkFloatArray>::New();
	evals = pca->GetEvals();
    
	for(int i = 0; i < evals->GetNumberOfTuples(); i++)
	{
		eigenValues.push_back( evals->GetTuple1(i) );
	}
    
    
	//accessing to EigenVectors
	
#if VTK_MAJOR_VERSION > 5
	vtkMultiBlockDataSet* block = pca->GetOutput();
#endif
	for (int i = 0; i < numberOfModes; i++){
        #if VTK_MAJOR_VERSION <= 5
		vtkPointSet* evecs = pca->GetOutput(i);
        #else
        	vtkPointSet* evecs = vtkPointSet::SafeDownCast(block->GetBlock(i));
        #endif
	}


Could you tell me if this is the correct way to set the filter?

Best regards,

Waldo.

On 15 Apr 2014, at 16:03, Bill Lorensen <bill.lorensen at gmail.com> wrote:

> What errors do you get when you try this with vtk6?
> 
> On Tue, Apr 15, 2014 at 5:08 AM, Waldo Valenzuela
> <waldo.valenzuela at hotmail.com> wrote:
>> Hey Guys,
>> 
>> I am migrating my code from vtk 5.1.0 to vtk 6.1.0 and I have my first problem. I am doing statistical shape modelling using vtkPCAAnalysisFilter, but I don’t know how configure in vtk 6 this filter. Here I have a example how I was using before.
>> 
>> // ===============================================================
>> shapeVariations variable is a vector with vtkpolydata, different meshes already aligned.
>> // do PCA
>>        vtkSmartPointer<vtkPCAAnalysisFilter> pca;
>>        pca = vtkSmartPointer<vtkPCAAnalysisFilter>::New();
>> 
>>        pca->SetNumberOfInputs( numberOfShapeVariations );
>> 
>>        for (int i = 0; i < numberOfShapeVariations; i++){
>>                pca->SetInput(i, shapeVariations[i]);
>>        }
>> 
>>        std::cout<<"Start PCA"<<std::endl;
>>        pca->Update();
>>        std::cout<<"Finished PCA"<<std::endl;
>> 
>> 
>>        numberOfModes = shapeVariations.size();
>> 
>>        //setEigenValues
>> 
>>        eigenValues.clear();
>> 
>>        vtkSmartPointer<vtkFloatArray> evals = vtkSmartPointer<vtkFloatArray>::New();
>>        evals = pca->GetEvals();
>> 
>> // reading eigen values
>>        for(int i = 0; i < evals->GetNumberOfTuples(); i++)
>>        {
>>                float value = evals->GetTuple1(i);
>>        }
>> 
>> 
>>        //reading EigenVectors
>> 
>> 
>>        for (int i = 0; i < numberOfModes; i++){
>>                vtkPointSet* evecs = pca->GetOutput(i);
>>        }
>> // ===============================================================
>> Someone know some example of this filter for vtk 6.1.0?
>> 
>> I will really appreciate any help on this subject.
>> 
>> Best regards,
>> 
>> Waldo
>> _______________________________________________
>> 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
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 
> 
> -- 
> Unpaid intern in BillsBasement at noware dot com
> 



More information about the vtkusers mailing list