How to set 2d CDT to alow interception of constraints? - constraints

I´m changing a 2D CDT terrain from constraints that don´t intercept to constraints that can intercept.
I changed:
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Constrained_Delaunay_triangulation_2<K> CDT;
to
typedef CGAL::Exact_predicates_exact_constructions_kernel EK;
typedef CGAL::Constrained_Delaunay_triangulation_2<EK,TDS,Itag> CDT;
typedef CGAL::Constrained_triangulation_plus_2<CDT> CDTP;
and all:
typedef typedef CDT::<...>
to
typedef CDTP::<...>
When I use the class Point to get the coordinates of a point for example:
bool operator()(const Point & p1, const Point & p2) const
{
double x = p1.x(); //<--- Error on this line
...
}
The compiler is issuing the error:
there is no convertion from CGAL::Lazy_exact_ntboost::multiprecision::mpq_rational to double
I did a reserch on this issue but had no success to fix this error.
Can anyone tell me how to fix it?
thanks in advance

Itag is the parameter that is controlling the behavior of the code if constraints are intersecting (see the doc). So if you have a working code without intersection using EPICK, changing Itag to Exact_predicates_tag is the only change needed.

Related

Setting normals for ISSKeypoint3D in Point Cloud Library (PCL)

I'm trying to compute ISS3D keypoints on a point cloud in PCL. I want to set
the normals because I'm not sure if the ISS keypoint estimation flips them
in the correct direction. However, when I try to set the normals like this
typedef pcl::PointCloud<pcl::PointXYZRGB> > PointCloud;
PointCloud::Ptr detecISSKeypoints(PointCloud::Ptr cloud, pcl::PointCloud<pcl::PointNormal>::Ptr normals, float resolution) {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr keypoints(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::ISSKeypoint3D<pcl::PointXYZRGB, pcl::PointXYZRGB> detector;
detector.setInputCloud(cloud);
detector.setNormals(normals);
pcl::search::KdTree<pcl::PointXYZRGB>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZRGB>);
detector.setSearchMethod(kdtree);
detector.setSalientRadius(6 * resolution);
detector.setNonMaxRadius(6 * resolution);
detector.setMinNeighbors(6);
detector.setThreshold21(0.975);
detector.setThreshold32(0.975);
detector.setNumberOfThreads(4);
detector.compute(*keypoints);
return keypoints;
}
I get an error that setNormals is expecting a const PointCloudNConstPtr&. I tried to convert the pointer of the normals to const pcl::PointCloud<pcl::PointNormal>::ConstPtr, however this didn't work.
How can I set the normals?
Finally I managed to set the normals like this:
pcl::PointCloud<pcl::Normal>::Ptr normalsCopy (new pcl::PointCloud<pcl::Normal>);
copyPointCloud(*normals, *normalsCopy);
boost::shared_ptr<const pcl::PointCloud<pcl::Normal> > constNormals (normalsCopy);
detector.setNormals(constNormals);
The problem is ISSKeypoint3D is only accepting pcl::Normal, not pcl::PointNormal and the pointer must be to a constant pointlcoud.

Casting void pointer

I have a struct
struct GROUP_POINTS
{
unsigned char number_of_points;
void *points;
};
struct GROUP_POINTS group_points;
The reason for points being a void pointer is that I want to keep the groups as general as possible, and setting the "link" to the correct struct at runtime.
One of the other structs is:
struct POINT_A
{
unsigned char something;
};
I can make another pointer that points to the *points to get access to the struct like :
struct POINT_A *point_a = (struct POINT_A *)group_points.points;
and then access the points by doing :
(*point_a).number_of_points = 5;
But I would really like to be able to use it like this:
group_points.points.number_of_points
So not needing the second pointer just to point to the void pointer. Is there any way to do this ?
Assuming the language is C++, you may want to consider template solution like that:
template <class T>
struct GROUP_POINTS
{
unsigned char number_of_points;
T *points;
};
typedef GROUP_POINTS<unsigned char> POINT_A;
//another typedefs for another points.
Also, you probably would be fine with just std::vector<T> instead of whole points structs, but just to illustrate general approach this is how it can be done.
Since all you need is to avoid using another pointer, you can use it like this:
((struct POINT_A *)group_points).points.number_of_points = 5;
Note that the type cast has a lower precedence than that of the . operator, the parenthesis is necessary.

CGAL: Remove constraints in triangulation according to some face property

Suppose I have a constrained Delaunay triangulation where the facets are associated to some 'label' (some abstract property). I want to remove from the constraints the edges which are incident to facets that share the same labels. What is an efficient approach to do it, and how to make sure the facets obtained after a constrained is removed keeps its label?
Here is an piece of code apadted from a CGAL example to illustrate my purpose:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>
#include <CGAL/Polygon_2.h>
#include <iostream>
struct FaceInfo2
{
FaceInfo2(){}
int label;
};
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<FaceInfo2,K> Fbb;
typedef CGAL::Constrained_triangulation_face_base_2<K,Fbb> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
typedef CDT::Point Point;
typedef CGAL::Polygon_2<K> Polygon_2;
void insert_polygon(CDT& cdt,const Polygon_2& polygon)
{
if ( polygon.is_empty() ) return;
CDT::Vertex_handle v_prev=cdt.insert(*CGAL::cpp11::prev(polygon.vertices_end()));
for (Polygon_2::Vertex_iterator vit=polygon.vertices_begin();
vit!=polygon.vertices_end();++vit)
{
CDT::Vertex_handle vh=cdt.insert(*vit);
cdt.insert_constraint(vh,v_prev);
v_prev=vh;
}
}
void compute_labels(CDT& cdt)
{
// Do stuff and set the 'label' of each facet according to some property
}
int main( )
{
// Insert some polyons into a constrained triangulation
CDT cdt;
insert_polygon(cdt,polygon1);
insert_polygon(cdt,polygon2); // ...
// Mark facets according to an arbitrary property
compute_labels(cdt);
int count=0;
for (CDT::Finite_edges_iterator eit=cdt.finite_edges_begin();
eit!=cdt.finite_edges_end();++eit)
{
// This will not do, because the iterator may get invalidated
if ( eit->first->info().label == eit->first->neighbor(eit->second)->info().label )
cdt.remove_constrained_edge(eit->first, eit->second);
}
return 0;
}
I see several possibilties from there on:
Build a new CDT by inserting constrains that only join faces with different labels in the original triangulation.
Use the variant cdt.remove_constrained_edge(fh, i, out) to recover the facets possibly affected by the constraint removal, and treat them accordingly (but it still leaves the issue of the iterator being invalidated).
Use a BFS/DFS traversal of the facets coupled with the previous remark, but I still I'd still need to know which queued/stacked facet was affected by each constraint removal.
Use a set instead of a queue / stack during the traversal, so I can remove from facets I need to visit the handle to facets incident to a removed constraint (before removal), since after the removal they may be invalidated (if a flip occurs).
So, what do StackOverflow think about this?

Does CUDA support pointer-aliasing?

The reason why I ask this is because there is some strange bug in my code and I suspect it could be some aliasing problem:
__shared__ float x[32];
__shared__ unsigned int xsum[32];
int idx=threadIdx.x;
unsigned char * xchar=(unsigned char *)x;
//...do something
if (threadIdx.x<32)
{
xchar[4*idx]&=somestring[0];
xchar[4*idx+1]&=somestring[1];
xchar[4*idx+2]&=somestring[2];
xchar[4*idx+3]&=somestring[3];
xsum[idx]+=*((unsigned int *)(x+idx));//<-Looks like the compiler sometimes fail to recongize this as the aliasing of xchar;
};
The compiler only needs to honour aliasing between compatible types. Since char and float are not compatible, the compiler is free to assume the pointers never alias.
If you want to do bitwise operations on float, firstly convert (via __float_as_int()) to unsigned integer, then operate on that, and finally convert back to float (using __int_as_float()).
I think you have a race condition here. But I don't know what is somestring. If it is the same for all threads you can do like this:
__shared__ float x[32];
unsigned char * xchar=(unsigned char *)x;
//...do something
if(threadIdx.x<4) {
xchar[threadIdx.x]&=somestring[threadIdx.x];
}
__syncthreads();
unsigned int xsum+=*((unsigned int *)x);
It means that every thread shares the same array and therefore, xsum is the same between all threads. If you want that each thread has its own array, you have to allocate an array of 32*number_of_threads_in_block and use an offset.
PS: the code above works only in 1D block. In 2D or 3D you have to compute you own threadID and be sure that only 4 threads execute the code.

Bad output taylor series sinx

i'm trying to write a program that gets from the user a value x and prints sinx using taylor series. but my output is bad. the output i get is not even a number, its -1.#IND00 regardless of what i input.
here's my code
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
double x,sum,last;
sum=(double)0;
scanf("%f",&x);
last=x;
sum=last;
for(i=1;i<10;i++)
{
last*=(double)(-x*x)/((2*i)*(2*i+1));
sum+=last;
}
printf("%f",sum);
getch();
}
I can see one problem:
scanf("%f",&x);
x is a double, so you need the l, i.e. "%lf".
[true but irrelevant point about how this isn't the right formula for sinh, even though sinh is nowhere mentioned in the question, redacted..]

Resources