![](/img/trans.png)
[英]How to pass efficiently a subvector of std::vector<cv::Point3f> as parameter (don't own function)
[英]How to pass vtkMatrix and std::vector<cv::Point3f> as function parameters?
我有一個類頭文件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聲明為私有屬性嗎? 我被困在這一點上。
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.