Blender V2.61 - r43446

subd_vert.h

Go to the documentation of this file.
00001 /*
00002  * Original code in the public domain -- castanyo@yahoo.es
00003  * 
00004  * Modifications copyright (c) 2011, Blender Foundation.
00005  * All rights reserved.
00006  * 
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  * * Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * * Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * 
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00017  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00018  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00019  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00020  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00021  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef __SUBD_VERTEX_H__
00030 #define __SUBD_VERTEX_H__
00031 
00032 #include "subd_edge.h"
00033 #include "subd_mesh.h"
00034 
00035 CCL_NAMESPACE_BEGIN
00036 
00037 /* Subd Vertex */
00038 
00039 class SubdVert
00040 {
00041 public:
00042     int id;
00043     float3 co;
00044     
00045     SubdEdge *edge;
00046     SubdVert *next;
00047     SubdVert *prev;
00048 
00049     SubdVert(int id_)
00050     {
00051         id = id_;
00052         edge = NULL;
00053         co = make_float3(0.0f, 0.0f, 0.0f);
00054 
00055         next = this;
00056         prev = this;
00057     }
00058     
00059     /* valence */
00060     int valence()
00061     {
00062         int num = 0;
00063 
00064         for(EdgeIterator it(edges()); !it.isDone(); it.advance())
00065             num++;
00066 
00067         return num;
00068     }
00069 
00070     /* edge queries */
00071     bool is_boundary() { return (edge && !edge->face); }
00072 
00073     /* iterator over edges in counterclockwise order */
00074     class EdgeIterator
00075     {
00076     public:
00077         EdgeIterator(SubdEdge *e) : end(NULL), cur(e) { }
00078 
00079         virtual void advance()
00080         {
00081             if(end == NULL) end = cur;
00082             cur = cur->pair->next;
00083             //cur = cur->prev->pair;
00084         }
00085 
00086         virtual bool isDone() { return end == cur; }
00087         virtual SubdEdge *current() { return cur; }
00088 
00089     private:
00090         SubdEdge *end;
00091         SubdEdge *cur;
00092     };
00093 
00094     /* iterator over edges in clockwise order */
00095     class ReverseEdgeIterator
00096     {
00097     public:
00098         ReverseEdgeIterator(SubdEdge *e) : end(NULL), cur(e) { }
00099 
00100         virtual void advance()
00101         {
00102             if(end == NULL) end = cur;
00103             cur = cur->prev->pair;
00104         }
00105 
00106         virtual bool isDone() { return end == cur; }
00107         virtual SubdEdge *current() { return cur; }
00108 
00109     private:
00110         SubdEdge *end;
00111         SubdEdge *cur;
00112     };
00113 
00114     EdgeIterator edges() { return EdgeIterator(edge); }
00115     EdgeIterator edges(SubdEdge *edge) { return EdgeIterator(edge); }
00116 };
00117 
00118 CCL_NAMESPACE_END
00119 
00120 #endif /* __SUBD_VERTEX_H__ */
00121