Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: collada_edge/cross/conditioner.cpp

Issue 3083012: Tidying up. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « collada_edge/cross/collada_edge.cpp ('k') | converter/cross/renderer_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above 11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
14 * distribution. 14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its 15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from 16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission. 17 * this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 #include "precompile.h" 31 #include "precompile.h"
32 32
33 #include "conditioner.h" 33 #include "conditioner.h"
34 34
35 #include <cstdio> 35 #include <cstdio>
36 #include <map> 36 #include <map>
37 #include <vector> 37 #include <vector>
38 38
39 const float kEpsilon = 0.001f; 39 const float kEpsilon = 0.001f;
40 static const float kPi = 3.14159265358979f; 40 static const float kPi = 3.14159265358979f;
(...skipping 22 matching lines...) Expand all
63 indices.push_back(i1); 63 indices.push_back(i1);
64 indices.push_back(i2); 64 indices.push_back(i2);
65 } else { 65 } else {
66 pts.push_back(p2); 66 pts.push_back(p2);
67 pts.push_back(p1); 67 pts.push_back(p1);
68 indices.push_back(i2); 68 indices.push_back(i2);
69 indices.push_back(i1); 69 indices.push_back(i1);
70 } 70 }
71 } 71 }
72 72
73 // less than operator overload, necessary function for edge-triangle map. 73 // Less than operator overload, necessary function for edge-triangle map.
74 bool operator<(const Edge& left, const Edge& right) { 74 bool operator<(const Edge& left, const Edge& right) {
75 // compare two edges by their actually coordinates. 75 // compare two edges by their actually coordinates.
76 if (dist(left.pts[0], right.pts[0]) < kEpsilon) { 76 if (dist(left.pts[0], right.pts[0]) < kEpsilon) {
77 if (fabs(left.pts[1].getX() - right.pts[1].getX()) < kEpsilon) { 77 if (fabs(left.pts[1].getX() - right.pts[1].getX()) < kEpsilon) {
78 if (fabs(left.pts[1].getY() - right.pts[1].getY()) < kEpsilon) { 78 if (fabs(left.pts[1].getY() - right.pts[1].getY()) < kEpsilon) {
79 return left.pts[1].getZ() < right.pts[1].getZ(); 79 return left.pts[1].getZ() < right.pts[1].getZ();
80 } 80 }
81 return left.pts[1].getY() < right.pts[1].getY(); 81 return left.pts[1].getY() < right.pts[1].getY();
82 } 82 }
83 return left.pts[1].getX() < right.pts[1].getX(); 83 return left.pts[1].getX() < right.pts[1].getX();
84 } else { 84 } else {
85 if (fabs(left.pts[0].getX() - right.pts[0].getX()) < kEpsilon) { 85 if (fabs(left.pts[0].getX() - right.pts[0].getX()) < kEpsilon) {
86 if (fabs(left.pts[0].getY() - right.pts[0].getY()) < kEpsilon) { 86 if (fabs(left.pts[0].getY() - right.pts[0].getY()) < kEpsilon) {
87 return left.pts[0].getZ() < right.pts[0].getZ(); 87 return left.pts[0].getZ() < right.pts[0].getZ();
88 } 88 }
89 return left.pts[0].getY() < right.pts[0].getY(); 89 return left.pts[0].getY() < right.pts[0].getY();
90 } 90 }
91 return left.pts[0].getX() < right.pts[0].getX(); 91 return left.pts[0].getX() < right.pts[0].getX();
92 } 92 }
93 } 93 }
94 94
95 // go through triangles who share this edge. And check whether 95 // Go through triangles who share this edge. And check whether
96 // the max normal angle is larger than the threshold. 96 // the max normal angle is larger than the threshold.
97 void CheckSharpEdge(const Edge& shared_edge, 97 void CheckSharpEdge(const Edge& shared_edge,
98 const std::vector<Triangle>& triangle_list, 98 const std::vector<Triangle>& triangle_list,
99 std::vector<Edge>* sharp_edges, float threshold) { 99 std::vector<Edge>* sharp_edges, float threshold) {
100 for (size_t i = 0; i < triangle_list.size(); i++) 100 for (size_t i = 0; i < triangle_list.size(); i++)
101 for (size_t j = i + 1; j < triangle_list.size(); j++) { 101 for (size_t j = i + 1; j < triangle_list.size(); j++) {
102 Triangle t1 = triangle_list[i]; 102 Triangle t1 = triangle_list[i];
103 Triangle t2 = triangle_list[j]; 103 Triangle t2 = triangle_list[j];
104 int same_vertices_count = 0; 104 int same_vertices_count = 0;
105 // Same triangle might be stored twice to represent inner and 105 // Same triangle might be stored twice to represent inner and
(...skipping 26 matching lines...) Expand all
132 Vector3 n2 = cross(v22, v23); 132 Vector3 n2 = cross(v22, v23);
133 float iAngle = acos(dot(n1, n2) / (length(n1) * length(n2))); 133 float iAngle = acos(dot(n1, n2) / (length(n1) * length(n2)));
134 iAngle = iAngle * 180 / kPi; 134 iAngle = iAngle * 180 / kPi;
135 if (iAngle >= threshold) { 135 if (iAngle >= threshold) {
136 sharp_edges->push_back(shared_edge); 136 sharp_edges->push_back(shared_edge);
137 return; 137 return;
138 } 138 }
139 } 139 }
140 } 140 }
141 141
142 // insert edge-triangle pair to edge triangle map. 142 // Insert edge-triangle pair to edge triangle map.
143 void InsertEdgeTrianglePair(const Edge& edge, const Triangle& triangle, 143 void InsertEdgeTrianglePair(const Edge& edge, const Triangle& triangle,
144 std::map<Edge, std::vector<Triangle>>* et_map) { 144 std::map<Edge, std::vector<Triangle>>* et_map) {
145 std::map<Edge, std::vector<Triangle>>::iterator iter1 = 145 std::map<Edge, std::vector<Triangle>>::iterator iter1 =
146 et_map->find(edge); 146 et_map->find(edge);
147 if (iter1 == et_map->end()) { 147 if (iter1 == et_map->end()) {
148 std::vector<Triangle> same_edge_triangle_list; 148 std::vector<Triangle> same_edge_triangle_list;
149 same_edge_triangle_list.push_back(triangle); 149 same_edge_triangle_list.push_back(triangle);
150 et_map->insert(make_pair(edge, same_edge_triangle_list)); 150 et_map->insert(make_pair(edge, same_edge_triangle_list));
151 } else { 151 } else {
152 iter1->second.push_back(triangle); 152 iter1->second.push_back(triangle);
153 } 153 }
154 } 154 }
155 155
156 NodeInstance* CreateInstanceTree(FCDSceneNode *node) { 156 NodeInstance* CreateInstanceTree(FCDSceneNode *node) {
157 NodeInstance *instance = new NodeInstance(node); 157 NodeInstance *instance = new NodeInstance(node);
158 NodeInstance::NodeInstanceList &children = instance->children(); 158 NodeInstance::NodeInstanceList &children = instance->children();
159 for (size_t i = 0; i < node->GetChildrenCount(); ++i) { 159 for (size_t i = 0; i < node->GetChildrenCount(); ++i) {
160 FCDSceneNode *child_node = node->GetChild(i); 160 FCDSceneNode *child_node = node->GetChild(i);
161 NodeInstance *child_instance = CreateInstanceTree(child_node); 161 NodeInstance *child_instance = CreateInstanceTree(child_node);
162 children.push_back(child_instance); 162 children.push_back(child_instance);
163 } 163 }
164 return instance; 164 return instance;
165 } 165 }
166 166
167 // go through all polygons in geom_instance, and add all sharp edges 167 // Go through all polygons in geom_instance, and add all sharp edges
168 // as a new polygon in geom. And also, add material and effect based 168 // as a new polygon in geom. And also, add material and effect based
169 // on the given sharpEdgeColor option. 169 // on the given sharpEdgeColor option.
170 void BuildSharpEdge(FCDocument* doc, FCDGeometryInstance* geom_instance, 170 void BuildSharpEdge(FCDocument* doc, FCDGeometryInstance* geom_instance,
171 const Options& options) { 171 const Options& options) {
172 FCDGeometry* geom = static_cast<FCDGeometry*>(geom_instance->GetEntity()); 172 FCDGeometry* geom = static_cast<FCDGeometry*>(geom_instance->GetEntity());
173 if (!(geom && geom->IsMesh())) 173 if (!(geom && geom->IsMesh()))
174 return; 174 return;
175 FCDGeometryMesh* mesh = geom->GetMesh(); 175 FCDGeometryMesh* mesh = geom->GetMesh();
176 FCDGeometryPolygonsTools::Triangulate(mesh); 176 FCDGeometryPolygonsTools::Triangulate(mesh);
177 FCDGeometryPolygonsTools::GenerateUniqueIndices(mesh, NULL, NULL); 177 FCDGeometryPolygonsTools::GenerateUniqueIndices(mesh, NULL, NULL);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 360 }
361 } else { 361 } else {
362 printf("Error: couldn't open the input file.\n"); 362 printf("Error: couldn't open the input file.\n");
363 } 363 }
364 doc->Release(); 364 doc->Release();
365 } else { 365 } else {
366 printf("Internal error: Couldn't create FCollada document.\n"); 366 printf("Internal error: Couldn't create FCollada document.\n");
367 } 367 }
368 FCollada::Release(); 368 FCollada::Release();
369 return retval; 369 return retval;
370 } 370 }
371
OLDNEW
« no previous file with comments | « collada_edge/cross/collada_edge.cpp ('k') | converter/cross/renderer_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698