add BLI_strcpy_rlen, replace strcat, which was used in misleading way.
[blender.git] / intern / cycles / subd / subd_vert.h
1 /*
2  * Original code in the public domain -- castanyo@yahoo.es
3  * 
4  * Modifications copyright (c) 2011, Blender Foundation.
5  * All rights reserved.
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  * * Redistributions of source code must retain the above copyright
11  *   notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  * 
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #ifndef __SUBD_VERTEX_H__
30 #define __SUBD_VERTEX_H__
31
32 #include "subd_edge.h"
33 #include "subd_mesh.h"
34
35 CCL_NAMESPACE_BEGIN
36
37 /* Subd Vertex */
38
39 class SubdVert
40 {
41 public:
42         int id;
43         float3 co;
44         
45         SubdEdge *edge;
46         SubdVert *next;
47         SubdVert *prev;
48
49         SubdVert(int id_)
50         {
51                 id = id_;
52                 edge = NULL;
53                 co = make_float3(0.0f, 0.0f, 0.0f);
54
55                 next = this;
56                 prev = this;
57         }
58         
59         /* valence */
60         int valence()
61         {
62                 int num = 0;
63
64                 for(EdgeIterator it(edges()); !it.isDone(); it.advance())
65                         num++;
66
67                 return num;
68         }
69
70         /* edge queries */
71         bool is_boundary() { return (edge && !edge->face); }
72
73         /* iterator over edges in counterclockwise order */
74         class EdgeIterator
75         {
76         public:
77                 EdgeIterator(SubdEdge *e) : end(NULL), cur(e) { }
78
79                 virtual void advance()
80                 {
81                         if(end == NULL) end = cur;
82                         cur = cur->pair->next;
83                         //cur = cur->prev->pair;
84                 }
85
86                 virtual bool isDone() { return end == cur; }
87                 virtual SubdEdge *current() { return cur; }
88
89         private:
90                 SubdEdge *end;
91                 SubdEdge *cur;
92         };
93
94         /* iterator over edges in clockwise order */
95         class ReverseEdgeIterator
96         {
97         public:
98                 ReverseEdgeIterator(SubdEdge *e) : end(NULL), cur(e) { }
99
100                 virtual void advance()
101                 {
102                         if(end == NULL) end = cur;
103                         cur = cur->prev->pair;
104                 }
105
106                 virtual bool isDone() { return end == cur; }
107                 virtual SubdEdge *current() { return cur; }
108
109         private:
110                 SubdEdge *end;
111                 SubdEdge *cur;
112         };
113
114         EdgeIterator edges() { return EdgeIterator(edge); }
115         EdgeIterator edges(SubdEdge *edge) { return EdgeIterator(edge); }
116 };
117
118 CCL_NAMESPACE_END
119
120 #endif /* __SUBD_VERTEX_H__ */
121