From vertex pointers to vertex handles?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

From vertex pointers to vertex handles?

Tom Kazimiers
Hi,

like in the triangulation example "adding handles" I have my own data
structure as vertex for constrained 2D delaunay triangulations.
This works pretty good and I have only one problem: Most of the time I
deal with pointers to my vertices in the triangulation.
If I now want to call a method on the mesh like incident_vertices (
Vertex_handle v) I have to get a vertex_handle out of the pointer to the
vertex.

Is there a way to do this?

Thanks in advance,
Tom
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Manuel Caroli
Hi Tom,

I'm not sure I understand your problem well but I don't see a direct
solution here. Why don't you work with pointers to Vertex_handles or
directly with Vertex_handles?
Maybe it would be helpful if you could post some pieces of code to clarify.

Manuel


Tom Kazimiers wrote:

> Hi,
>
> like in the triangulation example "adding handles" I have my own data
> structure as vertex for constrained 2D delaunay triangulations.
> This works pretty good and I have only one problem: Most of the time I
> deal with pointers to my vertices in the triangulation.
> If I now want to call a method on the mesh like incident_vertices (
> Vertex_handle v) I have to get a vertex_handle out of the pointer to the
> vertex.
>
> Is there a way to do this?
>
> Thanks in advance,
> Tom

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Tom Kazimiers
Manuel,

thanks for your answer. My application deals with a vertex data
structure called ILaunchSite (it is an interface, actually). The data
handling should be done by CGAL. To avhive this I implemented my own
vertex_base class (like in the "adding handles" example):

template < class VertexBase = CGAL::Triangulation_vertex_base_2<K> >
        class CGALLaunchSite :
                public ILaunchSite<PrecisionType>,
                public VertexBase
            {
                ...
             };

Since I am not too experienced with C++ and didn't manage it to work
mostly with references to CGALLaunchSites, I work often with pointers to
this class. There are two concurenting data "managers". One is CGAL -
the other is something I tryed for testing and other purposes. However,
is it possible to do the same with Vertex_handles? Can I implement my
own vertex handle class? This would be great :)

Currently I don't know any way to do this and so I have a somewhere in
my app a pointer to an ILaunchSite (the interface, actually it is a
CGALLaunchSite). This pointer points to a vertex in a CGAL delaunay
triangulation. Now I want to get the neighbors of this vertex and  think
I should call incident_vertices (Vertex_handle v). It compiles when I
pass the pointer directly to the method but fails in runtime - a
NULL-Pointer check in the constructor of Vertex_handle found out that I
was not passing a NULL pointer - and he dislikes it ;)

Do you have any hints?

To have something to work with, I currently use a lookup table (a map)
to get the Vertex_handle I get from insertion from a pointer to a
CGALLaunchSite.

Regards and thanks,
Tom

Manuel Caroli schrieb:

> Hi Tom,
>
> I'm not sure I understand your problem well but I don't see a direct
> solution here. Why don't you work with pointers to Vertex_handles or
> directly with Vertex_handles?
> Maybe it would be helpful if you could post some pieces of code to
> clarify.
>
> Manuel
>
>
> Tom Kazimiers wrote:
>> Hi,
>>
>> like in the triangulation example "adding handles" I have my own data
>> structure as vertex for constrained 2D delaunay triangulations.
>> This works pretty good and I have only one problem: Most of the time I
>> deal with pointers to my vertices in the triangulation.
>> If I now want to call a method on the mesh like incident_vertices (
>> Vertex_handle v) I have to get a vertex_handle out of the pointer to the
>> vertex.
>>
>> Is there a way to do this?
>>
>> Thanks in advance,
>> Tom
>

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Daniel Duque
In reply to this post by Tom Kazimiers
On Sunday 22 March 2009 13:33:29 Tom Kazimiers wrote:
> If I now want to call a method on the mesh like incident_vertices (
> Vertex_handle v) I have to get a vertex_handle out of the pointer to the
> vertex.

Can't you just do:

Vertex_handle vh=&(*pv);

where pv is a pointer to a vertex?

Looks funny, but it may work.

Alternatively:

Vertex v=*pv;
Vertex_handle vh=&v;

Best,

Daniel

--
Nueva dirección de e-mail!

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

RE: From vertex pointers to vertex handles?

avaxman
Wouldn't

Vertex v=*pv

Create a copy of the vertex?

-----Original Message-----
From: Daniel Duque [mailto:[hidden email]]
Sent: Monday, March 23, 2009 11:11 AM
To: [hidden email]
Subject: Re: [cgal-discuss] From vertex pointers to vertex handles?

On Sunday 22 March 2009 13:33:29 Tom Kazimiers wrote:
> If I now want to call a method on the mesh like incident_vertices (
> Vertex_handle v) I have to get a vertex_handle out of the pointer to the
> vertex.

Can't you just do:

Vertex_handle vh=&(*pv);

where pv is a pointer to a vertex?

Looks funny, but it may work.

Alternatively:

Vertex v=*pv;
Vertex_handle vh=&v;

Best,

Daniel

--
Nueva dirección de e-mail!

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Daniel Duque
On Monday 23 March 2009 10:10:55 Amir Vaxman wrote:
> Wouldn't
>
> Vertex v=*pv
>
> Create a copy of the vertex?

Yes indeed. Not too efficient, but I guess it would work.

Best,

Daniel

--
Nueva dirección de e-mail!
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

SCHWARZ
If I understand your problem, you have 'p' a pointer to a vertex and
you would like to get a handle to that vertex. That is, you would like
to be able to do something like :
vertex_handle ph = p->vertex()

According to the documentation, if you try to insert a point that
coincides with an existing point, there is no insertion and you get a
handle to the already existing point :
 Vertex_handle    t.insert ( Point p, Face_handle f = Face_handle())
                Inserts point p in the triangulation and returns the corresponding vertex.
 If point p coincides with an already existing vertex, this vertex is
returned and the triangulation remains unchanged.

I am not very familiar with that package though. Maybe another way to
get your handles is to "hack" through facets :
facet_handle fh = p->facet();
then test all three vertices in that facet to get a handle to the
vertex that coincides with your p->point()

hope this helps

    --Ben
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Tom Kazimiers
In reply to this post by Daniel Duque
Daniel Duque schrieb:

> On Monday 23 March 2009 10:10:55 Amir Vaxman wrote:
>  
>> Wouldn't
>>
>> Vertex v=*pv
>>
>> Create a copy of the vertex?
>>    
>
> Yes indeed. Not too efficient, but I guess it would work.
>
> Best,
>
> Daniel
>
>  
Unfortunately does this not work - a debug assertion is violated (the
exact same thing as written before, Vertex_handle was expecting a NULL
pointer).

But thanks anyway :)
Tom
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Tom Kazimiers
In reply to this post by SCHWARZ
Benjamin schwarz schrieb:

> If I understand your problem, you have 'p' a pointer to a vertex and
> you would like to get a handle to that vertex. That is, you would like
> to be able to do something like :
> vertex_handle ph = p->vertex()
>
> According to the documentation, if you try to insert a point that
> coincides with an existing point, there is no insertion and you get a
> handle to the already existing point :
>  Vertex_handle    t.insert ( Point p, Face_handle f = Face_handle())
> Inserts point p in the triangulation and returns the corresponding vertex.
>  If point p coincides with an already existing vertex, this vertex is
> returned and the triangulation remains unchanged.
>
> I am not very familiar with that package though. Maybe another way to
> get your handles is to "hack" through facets :
> facet_handle fh = p->facet();
> then test all three vertices in that facet to get a handle to the
> vertex that coincides with your p->point()
>
> hope this helps
>
>     --Ben
>  
Ben,

thank you for your further suggestions. You understood my problem: I
have a Vertex pointer 'p' and want to get ists handle. More precise I
have a pointer to an object of my interface which is also a vertex - but
the type of the pointer I get is a pointer to my interface type
(ILaunchSite).

I tryed the insertion method and it works, thank you :) It would be
interesting to get some timings for what the fastest method would be. I
will compare the methods.

My problem with the facet method is that I get, like above said, a
pointer to my type and would need a cast for this. And I try to avoid
those little performance eaters. Well, on the other hand could this be a
result of using a static interface class instead of a templated type
(Which then would be the CGALLaunchSite implementation of ILaunchSite).

Regards,
Tom


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Tom Kazimiers
Tom Kazimiers schrieb:

> Benjamin schwarz schrieb:
>  
>> If I understand your problem, you have 'p' a pointer to a vertex and
>> you would like to get a handle to that vertex. That is, you would like
>> to be able to do something like :
>> vertex_handle ph = p->vertex()
>>
>> According to the documentation, if you try to insert a point that
>> coincides with an existing point, there is no insertion and you get a
>> handle to the already existing point :
>>  Vertex_handle    t.insert ( Point p, Face_handle f = Face_handle())
>> Inserts point p in the triangulation and returns the corresponding vertex.
>>  If point p coincides with an already existing vertex, this vertex is
>> returned and the triangulation remains unchanged.
>>
>> I am not very familiar with that package though. Maybe another way to
>> get your handles is to "hack" through facets :
>> facet_handle fh = p->facet();
>> then test all three vertices in that facet to get a handle to the
>> vertex that coincides with your p->point()
>>
>> hope this helps
>>
>>     --Ben
>>  
>>    
> Ben,
>
> thank you for your further suggestions. You understood my problem: I
> have a Vertex pointer 'p' and want to get ists handle. More precise I
> have a pointer to an object of my interface which is also a vertex - but
> the type of the pointer I get is a pointer to my interface type
> (ILaunchSite).
>
> I tryed the insertion method and it works, thank you :) It would be
> interesting to get some timings for what the fastest method would be. I
> will compare the methods.
>
> My problem with the facet method is that I get, like above said, a
> pointer to my type and would need a cast for this. And I try to avoid
> those little performance eaters. Well, on the other hand could this be a
> result of using a static interface class instead of a templated type
> (Which then would be the CGALLaunchSite implementation of ILaunchSite).
>
> Regards,
> Tom
>
>
>  
I compared the method with a lookup table and the insertion method - 400
points each:

No optimization:
Insert: 63,7883ms
Map: 5,69598ms

Optimized:
Insert: 15,143ms
Map: 0,129905

I guess I stay with the map :)

Regards and thanks,
Tom
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

SCHWARZ
Did you try to use the insert() method with the specification of a
facet to initialize the search process ? I mean, something like :

handle h = triangulation.insert(*p,p->facet())

I bet this will probably lessen your insertion time ;)
Anyway, maps are pretty fast indeed, so you will surely stay with this
solution in the end ;)

  --Ben
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Sylvain Pion
Administrator
In reply to this post by Tom Kazimiers
Tom Kazimiers wrote:

> I compared the method with a lookup table and the insertion method - 400
> points each:
>
> No optimization:
> Insert: 63,7883ms
> Map: 5,69598ms
>
> Optimized:
> Insert: 15,143ms
> Map: 0,129905
>
> I guess I stay with the map :)

Never give up !

Vertex_handle vertex_cast(Vertex* v)
{
  Cell_handle c = v->cell();
  if (&*(c->vertex(0)) == v) return c->vertex(0);
  if (&*(c->vertex(1)) == v) return c->vertex(1);
  if (&*(c->vertex(2)) == v) return c->vertex(2);
  assert( &*(c->vertex(3)) == v );
  return c->vertex(3);
}

(untested)


This is still kludgy, though.  I hope to find the time
to implement a straightforward solution for CGAL 3.5
(it's mostly done).

--
Sylvain Pion
INRIA Sophia-Antipolis
Geometrica Project-Team
CGAL, http://cgal.org/
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: From vertex pointers to vertex handles?

Tom Kazimiers
Sylvain Pion schrieb:

> Tom Kazimiers wrote:
>> I compared the method with a lookup table and the insertion method - 400
>> points each:
>>
>> No optimization:
>> Insert: 63,7883ms
>> Map: 5,69598ms
>>
>> Optimized:
>> Insert: 15,143ms
>> Map: 0,129905
>>
>> I guess I stay with the map :)
>
> Never give up !
>
> Vertex_handle vertex_cast(Vertex* v)
> {
>  Cell_handle c = v->cell();
>  if (&*(c->vertex(0)) == v) return c->vertex(0);
>  if (&*(c->vertex(1)) == v) return c->vertex(1);
>  if (&*(c->vertex(2)) == v) return c->vertex(2);
>  assert( &*(c->vertex(3)) == v );
>  return c->vertex(3);
> }
>
> (untested)
>
>
> This is still kludgy, though.  I hope to find the time
> to implement a straightforward solution for CGAL 3.5
> (it's mostly done).
>
Woohoo :) Thank you very much. Your solution is faster then the map (and
this is good for the memory footprint):
NonOptimized: 3,95972ms
Optimized: 0,110629ms

So, I think this is the version to take.

Bye,
Tom

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss