C++「クリッパー ライブラリ」( http://www.angusj.com/delphi/clipper.php ) を使用しようとしていますが、関数からクリッパー ライブラリのオブジェクトの 1 つを返そうとすると、 nullになるか、何らかの形で変更されます
ここに私が書いた関数があります。関連する行は最後の 3 行だけです。
ClipperLib::PolyTree MeshHandler::trianglesToPolyTreeUnion(std::vector<Triangle> triangles)
{
// Make all of the triangles CW
for (auto& triangle : triangles)
{
triangle.makeClockwise();
}
// Set up the Clipper
ClipperLib::Clipper clipper;
// To take a union, add all the paths as "subject" paths
for (auto& triangle : triangles)
{
ClipperLib::Path triContour(3);
triContour[0] = convertGLMToClipperPoint(triangle.getVertex(0));
triContour[1] = convertGLMToClipperPoint(triangle.getVertex(1));
triContour[2] = convertGLMToClipperPoint(triangle.getVertex(2));
clipper.AddPath(triContour, ClipperLib::PolyType::ptSubject, true);
}
// Now get the PolyTree representing the contours
ClipperLib::PolyTree tree;
clipper.Execute(ClipperLib::ClipType::ctUnion, tree);
return tree;
}
clipper.execute を呼び出すと、ツリー構造に輪郭情報が書き込まれます。それは正しい情報を書いており、私はそれが正しいことをテストしました。しかし、ツリーを返すと、何もコピーしていないようで、この関数の結果の PolyTree は空です。
ライブラリに問題はなく、ここで初心者の C++ の間違いを犯しているだけだと確信しています。うまくいけば、誰かがそれが何であるかについての考えを持っています.
ありがとう!
編集: 参考までに、ポリツリーのドキュメント ページを次に示します ( http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/PolyTree/_Body.htm )
編集: クリッパー ライブラリはオープン ソースではないと思っていましたが、そうです。ここにコードがあります
typedef std::vector< IntPoint > Path;
typedef std::vector< Path > Paths;
class PolyNode;
typedef std::vector< PolyNode* > PolyNodes;
class PolyNode
{
public:
PolyNode();
Path Contour;
PolyNodes Childs;
PolyNode* Parent;
PolyNode* GetNext() const;
bool IsHole() const;
bool IsOpen() const;
int ChildCount() const;
private:
unsigned Index; //node index in Parent.Childs
bool m_IsOpen;
JoinType m_jointype;
EndType m_endtype;
PolyNode* GetNextSiblingUp() const;
void AddChild(PolyNode& child);
friend class Clipper; //to access Index
friend class ClipperOffset;
};
class PolyTree: public PolyNode
{
public:
~PolyTree(){Clear();};
PolyNode* GetFirst() const;
void Clear();
int Total() const;
private:
PolyNodes AllNodes;
friend class Clipper; //to access AllNodes
};