简体   繁体   中英

How to pass vtkMatrix and std::vector<cv::Point3f> as function parameters?

I have a class header file myclass.h

#ifndef MYCLASS_H
#define MYCLASS_H

#include <iostream>
#include <math.h>
#include <vector>

#include <vtkSmartPointer.h>
#include <vtkMatrix4x4.h>

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv/cv.h>

class myclass
{
 public:
     double compute(vtkMatrix4x4 *transMat, std::vector<Point3f>* sourcePoints);
};

  #endif // MYCLASS_H

And my myclass.cpp is:

#include <myclass.h>
#include <iostream>
#include <math.h>
#include <vector>

#include <vtkSmartPointer.h>
#include <vtkMatrix4x4.h>

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv/cv.h>

using namespace std;

double myclass::compute(vtkMatrix4x4 *transMat, std::vector<Point3f>* sourcePoints)
{
  double x;
  ......code for computing x......
  ................................
  return x;
}

This returns error when I implement:

 myclass myFunctions;
 std::vector<cv::Point3f> sourcePoints;
 vtkSmartPointer<vtkMatrix4x4> mat =  vtkSmartPointer<vtkMatrix4x4>::New();
 ...........mat and sourcePoints filled..................
 double c = myFunctions.compute(mat, sourcePoints);

Should I declare the vtkMatrix and sourcePoints as private attributes in header file? I am stuck at this point.

  • if you are using smartpointers, you will have to stick with them. never try to 'pull out the pointer', please, you will wreck its internal refcounts (and defeat its purpose).
  • prefer to pass a vector by reference , not by pointer

class myclass
{
 public:
     double myclass::compute(vtkSmartPointer<vtkMatrix4x4> mat, const std::vector<Point3f>& sourcePoints)
};
double myclass::compute(vtkSmartPointer<vtkMatrix4x4> mat, const std::vector<Point3f>& sourcePoints)
{
  double x;
  ......code for computing x......
  ................................
  return x;
}

 // now you can call it in the desired way:   
 myclass myFunctions;
 std::vector<cv::Point3f> sourcePoints;
 vtkSmartPointer<vtkMatrix4x4> mat =  vtkSmartPointer<vtkMatrix4x4>::New();
 double c = myFunctions.compute(mat, sourcePoints);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM