简体   繁体   English

如何通过vtkMatrix和std :: vector <cv::Point3f> 作为功​​能参数?

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

I have a class header file myclass.h 我有一个类头文件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: 我的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;
}

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? 我应该在头文件中将vtkMatrix和sourcePoints声明为私有属性吗? 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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