簡體   English   中英

如何通過vtkMatrix和std :: vector <cv::Point3f> 作為功​​能參數?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM