For my thesis I am using some CGAL code written by another student a year ago. I cannot get it to build, however.
The function that is giving errors is the following:
std::set<Curve_handle> originatingCurves(PL_Arrangement arrangement, VertexHandleSet vertices)
{
std::set<Curve_handle> curves;
for (Vertex_handle vertex : vertices)
{
auto heStart = vertex->incident_halfedges();
auto heCurrent = vertex->incident_halfedges();
do
{
Halfedge_handle handle = static_cast<Halfedge_handle>(heCurrent);
//Unless the halfedge represents a piece of overlap between curves, it has only one originating curve
for (auto curve = arrangement.originating_curves_begin(handle); curve != arrangement.originating_curves_end(handle); curve++)
{
curves.emplace(static_cast<Curve_handle>(curve));
}
heCurrent++;
} while (heCurrent != heStart);
}
return curves;
}
with the line curves.emplace(static_cast<Curve_handle>(curve)); giving the following errors:
Severity Code Description Project File Line Suppression State
Error C2672 'std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::emplace': no matching overloaded function found CurvedNonograms c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\curvednonograms\curve_manipulation.cpp 222
Error C2440 'static_cast': cannot convert from 'CGAL::Arrangement_on_surface_with_history_2<GeomTraits_,CGAL::Arr_bounded_planar_topology_traits_2<GeomTraits_,Dcel>>::Originating_curve_iterator' to 'Curve_handle' CurvedNonograms c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\curvednonograms\curve_manipulation.cpp 222
The user defined types like Curve_handle are defined in the following header file:
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_algebraic_number_traits.h>
#include <CGAL/Arr_Bezier_curve_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Arrangement_with_history_2.h>
#include <CGAL/Arr_extended_dcel.h>
#include <CGAL/Iso_rectangle_2.h>
#include <CGAL/Arr_walk_along_line_point_location.h>
#include <CGAL/Arr_observer.h>
//#include <CGAL/basic.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
struct FaceData
{
FaceData ()
{
colored = false;
solved = false;
};
bool colored = false;
bool solved = false;
};
//// Bezier curve traits ////
typedef CGAL::CORE_algebraic_number_traits Nt_traits;
typedef Nt_traits::Rational NT;
typedef Nt_traits::Rational Rational;
typedef Nt_traits::Algebraic Algebraic;
//Simple_cartesian = for easier debugging, no ref counting, values directly in objects
typedef CGAL::Cartesian<Rational> Kernel;
typedef CGAL::Cartesian<Algebraic> Alg_kernel;
//typedef Kernel::Point_2 Rat_Point;
typedef CGAL::Arr_Bezier_curve_traits_2<Kernel, Alg_kernel, Nt_traits> Traits;
typedef Traits::Curve_2 Bezier;
typedef Traits::Point_2 Point;
typedef Kernel::Iso_rectangle_2 BoundingBox;
typedef CGAL::Arr_face_extended_dcel<Traits, FaceData> Dcel;
typedef CGAL::Arrangement_with_history_2<Traits, Dcel> Arrangement; //Not really used anymore, because of crashes/problems/bugs
//// Polyline traits ////
// Instantiate the traits class using a user-defined kernel
// and Segment_traits_2.
typedef CGAL::Exact_predicates_exact_constructions_kernel PL_Kernel;
typedef CGAL::Arr_segment_traits_2<PL_Kernel> Segment_traits;
typedef CGAL::Arr_polyline_traits_2<Segment_traits> PL_traits;
// Identical instantiation can be achieved using the default Kernel:
// typedef CGAL::Arr_polyline_traits_2<> Geom_traits_2;
typedef PL_traits::Point_2 PL_Point;
typedef PL_traits::Segment_2 Segment;
typedef PL_traits::Curve_2 Polyline;
typedef CGAL::Arr_extended_dcel<PL_traits, bool/*not used*/, double, FaceData> PL_Dcel;
typedef CGAL::Arrangement_with_history_2<PL_traits, PL_Dcel> PL_Arrangement; //This is now the only type of arrangement that we actually use
//Handles
typedef PL_Arrangement::Vertex_const_handle Vertex_handle;
typedef PL_Arrangement::Halfedge_const_handle Halfedge_handle;
typedef PL_Arrangement::Curve_const_handle Curve_handle;
//Point location
typedef CGAL::Arr_walk_along_line_point_location<PL_Arrangement> PointLocationAlg;
typedef CGAL::Arr_point_location_result<PL_Arrangement>::Type PointLocationResult;
//Less function to use for (vertex/halfedge/face) handle sets
template <class Handle> struct HandleLess
{
bool operator()(Handle a, Handle b)
{
return (a.ptr() - b.ptr() < 0);
}
};
typedef std::set<Vertex_handle, HandleLess<Vertex_handle>> VertexHandleSet;
//Arrangement observer that keeps the face colours correct
class FaceColorObserver : public CGAL::Arr_observer<PL_Arrangement>
{
private:
bool coloredBeforeMerge;
public:
FaceColorObserver(PL_Arrangement& arrangement) :
CGAL::Arr_observer<PL_Arrangement>(arrangement)
{}
virtual void after_split_face(Face_handle oldFace, Face_handle newFace, bool)
{
newFace->data().colored = oldFace->data().colored;
}
virtual void before_merge_face(Face_handle face1, Face_handle face2, Halfedge_handle)
{
//The assumption is that only same-color faces get merged
CGAL_precondition(face1->data().colored == face2->data().colored);
coloredBeforeMerge = face1->data().colored;// && face2->data().colored;
}
virtual void after_merge_face(Face_handle newFace)
{
newFace->data().colored = coloredBeforeMerge;
}
};
//Arrangement of line segments
typedef CGAL::Arrangement_2<Segment_traits> Seg_Arrangement;
Previous problems I had with the codebase had to do with me using a newer version of CGAL than the original student, so I suspect that that might be the problem here as well, but I don't know how I should replace the line of code.
Arrangement::Originating_curve_iterator (which is also defined as Arrangement::Originating_curve_handle) has a user-defined conversion to Arrangement::Curve_handle and another to Arrangement::Curve_const_handle, so there is no problem with the statement
curves.emplace(static_cast<Curve_handle>(curve));
However, in
for (auto curve = arrangement.originating_curves_begin(handle);
curve != arrangement.originating_curves_end(handle); curve++)
the compiler assumes that curve is a non-const iterator, so just replace 'auto' with 'Curve_handle' (which is defined as PL_Arrangement::Curve_const_handle).
CGAL::Arrangement_on_surface_with_history_2::Originating_curve_iterator inherits from I_Dereference_iterator.
A Curve_handle is a: PL_Arrangement::Curve_const_handle. And since that does not inherit from either CGAL::Arrangement_on_surface_with_history_2::Originating_curve_iterator or I_Dereference_iterator you cannot static_cast between the 2. static_cast can only be used for down/up casts within an inheritance hierarchy.
Related
I'm attempting to compile the code below, but the compiler gives the error
Struct.h:38:9: error: ‘priority_queue’ in namespace ‘std’ does not name a type
Several searches failed to reveal an answer so I'm hoping you guys can help out. The code was partially based on the sample code given at the c++ reference site.
struct aimedShot;
union moveFunc;
struct timeCommand;
struct aimedShot
{
void (*move) (Dot*, SDL_Event&, double x, double y);
double x;
double y;
};
//Holds the kind of function used
union moveFunc
{
void (*notAimed) (Dot*);
aimedShot aimed;
};
//Dot to be operated on and the appropriate operator with time
struct timeCommand
{
Dot* target;
moveFunc command;
int time;
bool type; //True indicates aimed (integer inputs), False indicates unaimed
};
class CompareCommand
{
public:
bool operator()(timeCommand& c1, timeCommand& c2) //Return true if c1 comes first
{
return (c1.time < c2.time);
}
};
typedef std::priority_queue< timeCommand, std::vector<timeCommand>, CompareCommand> commandTimeline;
To be able to use std::priority_queue<> class template you need to #include <queue> standard header.
I have posted this already one day ago but I did not know how to add a second question to my first question.
I get a forward declaration error. You told me that it should be no problem if I define my class in KdTree.h and my functions, structs, etc in KdTree.cpp. However it does not work so here I post my whole code:
This is my header:
#Includes <iostream>
#Includes others
using namespace TooN;
#ifndef KDTREE_H_
#define KDTREE_H_
class KdTree {
public:
KdTree(std::vector<TooN::Vector<3,GLfloat> > & ,size_t);
struct node;
struct temptask;
struct temphold;
struct ...;
double function(...);
...;
std::vector<node> nodes;
std::vector < int > searchInRadius(const TooN::Vector<3, GLfloat> &,float , const std::vector<TooN::Vector<3,GLfloat> > & );
};
#endif
So and this is my KdTree.cpp:
#include "KdTree.h"
KdTree::KdTree(std::vector<TooN::Vector<3,GLfloat> > & points, size_t pointssize){
const size_t stacksize = 200;
nodes.push_back(node());
temphold tasksarray[stacksize] = {0,pointssize-1,0,0};
int taskindex = 0;
...A lot more stuff
if (!is_leaf(n)){
do something;
}
}
And then my functions in KdTree.cpp
struct KdTree::node{
std::size_t a, b, c;
node() : a(-1), b(-1), c(-1) {}
bool is_leaf(const node &n){
return blablabla;
}
};
And here my first 3 Compiler messages:( :
jni/Visual/KdTree.cpp: In constructor 'KdTree::KdTree(const std::vector<TooN::Vector<3, float> >&, size_t)':
jni/Visual/KdTree.cpp:32:23: error: invalid use of incomplete type 'struct KdTree::node'
nodes.push_back(node());
^
In file included from jni/Visual/KdTree.cpp:8:0:
jni/Visual/KdTree.h:29:9: error: forward declaration of 'struct KdTree::node'
struct node;
^
jni/Visual/KdTree.cpp:33:54: error: elements of array 'KdTree::temphold tasksarray [200]' have incomplete type
temphold tasksarray[stacksize] = {0,pointssize-1,0,0}; //starting at firstpoint = 0 index, lastpoint = lastindex, nodenumber = 0 index, dim = x-dimension (i.e. 0)
And a lot more of these kind of messages.
The struct definitions must still occur before their first use in the .cpp file.
#include "KdTree.h"
struct KdTree::node{
std::size_t a, b, c;
node() : a(-1), b(-1), c(-1) {}
bool is_leaf(const node &n){
return blablabla;
}
};
KdTree::KdTree(std::vector<TooN::Vector<3,GLfloat> > & points, size_t pointssize){
...A lot more stuff
}
Put the implementation of node at the beginning of KdTree.cpp, or at least before its first use:
#include "KdTree.h"
struct KdTree::node {
// ...
};
KdTree::KdTree() {
// ...
}
I want to sort a std::map based on the data (second field). However the second field itself is a structure and I want to sort based on one of its elements. Based on what is suggested here and its reference, decided to copy the map to a vector and then use std::sort. Here is the class implementtion
#include <iostream>
#include <vector>
#include <map>
#include <utility>
class foo() {
foo() {}
void bar()
{
aDeltaMap theDeltaMap;
// insert some elements to theDeltaMap
aDeltaVector theDeltaVec( theDeltaMap.begin(), theDeltaMap.end() );
std::sort(theDeltaVec.begin(), theDeltaVec.end(), descend_rep<deltaPair>() ); //ERROR
}
private:
typedef struct entry {
entry( int r, int mc ) : rep(r), missCounter(mc) {}
int rep;
int missCounter;
} aDeltaEntry;
typedef std::map< int, aDeltaEntry > aDeltaMap;
typedef std::pair< int, aDeltaEntry > deltaPair;
typedef std::vector< deltaPair > aDeltaVector;
struct descend_rep
: std::binary_function<deltaPair,deltaPair,bool>
{
inline bool operator()(const deltaPair& lhs, const deltaPair& rhs) { return lhs.second.rep > rhs.second.rep; };
};
};
At the line of sort function, I get this error
error C2275: illegal use of this type as an expression
error C2059: syntax error : ')'
What did I missed?
One error is that descent_rep is not a class template, so you need to replace
descend_rep<deltaPair>()
by
descend_rep()
You should make descend_rep's bool operator() const too, since comparing its operands does not change its state.
I am new to c++ and SWIG
I am creating a python module using SWIG in windows environment.
After creating wrapper class (example_wrap.cxx). Started building using (python setup.py build_ext --inplace) for creating python module.
But I am getting *example_wrap.cxx(3090) : error C2062: type 'int' unexpected*
GradedComplex.h:
class GradedComplex
{
public:
typedef std::complex<double> dcomplex;
typedef Item<dcomplex> item_type;
typedef ItemComparator<dcomplex> comparator;
typedef std::set<item_type, comparator> grade_type;
private:
int n_;
std::vector<grade_type *> grade_;
std::vector<double> thre_;
public:
GradedComplex(int n, double *thre);
~GradedComplex();
void push(item_type item);
void avg(double *buf);
};
#endif
GradedComplex.cc
GradedComplex::GradedComplex(int n, double *thre)
{
n_ = n;
for (int i = 0; i < n_; ++i)
{
thre_.push_back(thre[i]);
grade_.push_back(new grade_type());
}
}
Then I build it for generating python module using SWIG.
Swig interface file (example.i)
GradedComplex(int n, double *thre);
I am not much expert in SWIG interface file
The wrapper class generated has large volume of code so i am pasting few.
code : example_wrap.cxx
3083: #define SWIG_FILE_WITH_INIT
3084: #include "Item.h"
3085: #include "GradedComplex.h"
3086: typedef std::complex<double> dcomplex;
3087: typedef Item<dcomplex> item_type;
3088: typedef ItemComparator<dcomplex> comparator;
3089: typedef std::set<item_type, comparator> grade_type;
3090: GradedComplex(int n, double *thre);
3091: void push(item_type item);
3092: void avg(double *buf);
3093: #include <string>
3094: #include <complex>
3095: #include <iostream>
3096: #if PY_VERSION_HEX >= 0x03020000
3097: # define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
3098: #else
3099: # define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
3100: #endif
The GradedComplex constructor:
GradedComplex::GradedComplex(int n, double *thre)
{
n_ = n;
for (int i = 0; i < n_; ++i)
{
thre_.push_back(thre[i]);
grade_.push_back(new grade_type());
}
}
Please suggest a to rectify this error
You apparently declared class GradedComplex somewhere in some header file (GradedComplex.h?)
Later you attempted to use this name in this line
GradedComplex(int n, double *thre);
To a human reader this line would probably look like an attempt to declare an independent function GradedComplex. Technically, it is legal to have a function with the same name as an existing class. However, since you specified no return type for this function, the compiler does not see this as a function declaration. The compiler thinks you are trying to declare an object of type GradedComplex with redundant parentheses around the declarator, as in
GradedComplex (a);
For this reason, the appearance of that int confuses it and leads to an error report about an unexpected int in line 3090.
What were you trying to do? If you were trying to define a constructor for GradedComplex, then you already know how to do it (you posted a correct definition yourself). What is the purpose of line 3090? Why did you write that line?
You can not have a function with no return type in c++. You should set a return type for the function GradedComplex. Constructors can not be declared like that.
I have an error that goes like this
In file included from Level.hpp:12,
from main.cpp:4:
Corridor.hpp: In method `void Game::Corridor::update()':
Corridor.hpp:41: invalid use of undefined type `class Game::Level'
Corridor.hpp:13: forward declaration of `class Game::Level'
Corridor.hpp:42: invalid use of undefined type `class Game::Level'
Corridor.hpp:13: forward declaration of `class Game::Level'
Corridor.hpp:43: invalid use of undefined type `class Game::Level'
Corridor.hpp:13: forward declaration of `class Game::Level'
Corridor.hpp:44: invalid use of undefined type `class Game::Level'
Corridor.hpp:13: forward declaration of `class Game::Level'
Corridor and Level are ...
// Corridor.hpp
#ifndef GAME_CORRIDOR_HPP
#define GAME_CORRIDOR_HPP
#include <Moot/Math.hpp>
//#include <Level.hpp>
#include <GameWindow.hpp>
namespace Game
{
class Level; // <-- LINE 13
class Corridor
{
static const unsigned int defaultLevelDepth = 800;
Moot::Math::Vector3D wp1, wp2, wp3, wp4;
Moot::Math::Vector2D sp1, sp2, sp3, sp4;
Level * p_level;
public:
Corridor(Moot::Math::Vector3D setFirstPoint, Moot::Math::Vector3D setSecondPoint)
{
wp1 = setFirstPoint;
wp2 = setSecondPoint;
wp3 = setFirstPoint;
wp3.z += defaultLevelDepth;
wp4 = setSecondPoint;
wp4.z += defaultLevelDepth;
}
void update() {
sp1 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp1); // <- LINE 41 etc.
sp2 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp2);
sp3 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp3);
sp4 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp4);
//p_level->getLevelCamera();
}
void draw()//const
{
Moot::Color tempColor;
windowInstance().graphics().drawQuad( sp1.x, sp1.y, tempColor,
sp2.x,sp2.y, tempColor,
sp3.x, sp3.y, tempColor,
sp4.x,sp4.y, tempColor, 1);
}
void setLevel(Level* setLevel) {
p_level = setLevel;
}
};
}
#endif
and
// Level.hpp
#ifndef GAME_LEVEL_HPP
#define GAME_LEVEL_HPP
#include <Moot/Forward.hpp>
#include <Moot/Window.hpp>
#include <Moot/Math.hpp>
#include <GameWindow.hpp>
#include <Camera.hpp>
#include <Corridor.hpp>
#include <Player.hpp>
#include <vector>
namespace Game
{
class Level
{
typedef Corridor* p_corridor;
typedef std::vector<p_corridor> CorridorList;
typedef CorridorList::reverse_iterator ReverseCorridorItter;
CorridorList m_map;
Camera m_camera;
Player m_player;
public:
Level()
{
m_player.setLevel(this);
// Lots of vertices being defined into m_map.
// Loop through and set camera
ReverseCorridorItter rit;
for(rit = m_map.rbegin(); rit != m_map.rend(); rit++)
(*rit)->setLevel(this);
}
~Level()
{
ReverseCorridorItter rit;
for(rit = m_map.rbegin(); rit != m_map.rend(); rit++)
delete (*rit);
m_map.clear();
}
void update()
{
// Temp delete when input and player are implimented.
if(pad[0].buttons & PAD_UP)
m_camera.updateTargetOffsets(0, -2);
if(pad[0].buttons & PAD_DOWN)
m_camera.updateTargetOffsets(0, 2);
if(pad[0].buttons & PAD_LEFT)
m_camera.updateTargetOffsets(-2, 0);
if(pad[0].buttons & PAD_RIGHT)
m_camera.updateTargetOffsets(2, 0);
m_player.update();
ReverseCorridorItter rit;
for (rit = m_map.rbegin(); rit != m_map.rend(); rit++)
(*rit)->update();
}
void draw() // const // EH!!! wtf ReverseIter isn't a member
{
m_player.draw();
ReverseCorridorItter rit;
for (rit = m_map.rbegin(); rit != m_map.rend(); rit++)
(*rit)->draw();
}
Camera& getLevelCamera() {
return m_camera;
}
};
}
#endif
The pointer is being set as far as I can tell, but when I try to access a function from Level, BOOM!
Thanks.
PS: The compiler is gcc 2.95.2 if that makes a difference.
EDIT
Updated with complete code.
You are #include-ing Level's complete declaration:
#include <Level.hpp>
...and then you try to forward-declare Level:
namespace Game
{
class Level;
Don't do this. Choose one or the other. (edit) Or at least put the forward-declaration before the #include-ion of the complete declaration. If all you're doing in game_corridor.hpp is setting pointers to a Level, then a forward declare should do fine. If however you need to call functions on Level from within the HPP file, then you'll need to #include the complete declaration.
EDIT2:
Based on your clarifying edit to your OP, you must #include the complete declaration of Level, and not try to use a forward declaration.
If you forward-declare Game::Level then don't #include it. In a not-so-related note, use #include "header.hpp", not #include <header.hpp>.
Edit as per your updates: Bring the definition of Game::Corridor::update() outside the header and into an implementation file. This way the compile need not know anything about Game::Level apart from the fact that it exists and it's a type.
The problem is that Corridor doesn't know what a Level is, because it can't really #include Level.hpp, because Level.hpp is what #included Corridor.hpp.
The underlying problem is that you're trying to #include a source file. The really underlying problem is that you're using #include when you haven't separated your code into source files and header files. Here's how to split it up. (I'm assuming you're familiar with compiling source files into object files, then linking them into executables.)
Corridor.hpp:
#ifndef GAME_CORRIDOR_HPP
#define GAME_CORRIDOR_HPP
#include <Moot/Math.hpp>
#include <Level.hpp>
namespace Game
{
class Level;
class Corridor
{
static const unsigned int defaultLevelDepth = 800;
Moot::Math::Vector3D wp1, wp2, wp3, wp4;
Moot::Math::Vector2D sp1, sp2, sp3, sp4;
Level * p_level;
public:
Corridor(Moot::Math::Vector3D setFirstPoint, Moot::Math::Vector3D setSecondPoint);
void update();
void draw();
void setLevel(Level* setLevel);
};
}
#endif
Corridor.cpp:
#include "Corridor.hpp"
namespace Game
{
Corridor::Corridor(Moot::Math::Vector3D setFirstPoint, Moot::Math::Vector3D setSecondPoint)
{
wp1 = setFirstPoint;
wp2 = setSecondPoint;
wp3 = setFirstPoint;
wp3.z += defaultLevelDepth;
wp4 = setSecondPoint;
wp4.z += defaultLevelDepth;
}
void Corridor::update()
{
sp1 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp1);
sp2 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp2);
sp3 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp3);
sp4 = p_level->getLevelCamera().convert3DVectorWithScreenAlgorithm(wp4);
}
// and so on
}