如何将vtkMatrix和std :: vector <cv :: point3f>作为函数参数传递?</cv :: point3f>

时间:2014-10-01 05:36:59

标签: c++ class opencv vtk

我有一个类头文件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

我的myclass.cpp是:

#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;
}

执行时会返回错误:

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

我应该将vtkMatrix和sourcePoints声明为头文件中的私有属性吗?我被困在这一点上。

1 个答案:

答案 0 :(得分:2)

  • 如果您使用的是智能指针,则必须坚持永远不会尝试拔出指针,请你破坏其内部引用(并击败其目的)。
  • 更喜欢通过引用传递矢量,而不是通过指针传递

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);