Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
KennethVanhoey
CGoGN
Commits
887aa340
Commit
887aa340
authored
Nov 07, 2011
by
Pierre Kraemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Traversor pour calcul de normales et BB
parent
8906fc73
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
104 deletions
+54
-104
include/Algo/Geometry/boundingbox.h
include/Algo/Geometry/boundingbox.h
+4
-9
include/Algo/Geometry/normal.hpp
include/Algo/Geometry/normal.hpp
+36
-54
include/Algo/Render/GL2/mapRender.hpp
include/Algo/Render/GL2/mapRender.hpp
+13
-40
include/Topology/generic/traversor2.h
include/Topology/generic/traversor2.h
+1
-1
No files found.
include/Algo/Geometry/boundingbox.h
View file @
887aa340
...
...
@@ -27,7 +27,7 @@
#include "Geometry/basic.h"
#include "Geometry/bounding_box.h"
#include "Topology/generic/
cellmarker
.h"
#include "Topology/generic/
traversorCell
.h"
namespace
CGoGN
{
...
...
@@ -42,17 +42,12 @@ template <typename PFP>
Geom
::
BoundingBox
<
typename
PFP
::
VEC3
>
computeBoundingBox
(
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
position
,
const
FunctorSelect
&
select
=
SelectorTrue
())
{
Geom
::
BoundingBox
<
typename
PFP
::
VEC3
>
bb
;
CellMarker
vmarker
(
map
,
VERTEX
);
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
TraversorV
<
typename
PFP
::
MAP
>
t
(
map
)
;
for
(
Dart
d
=
t
.
begin
();
d
!=
t
.
end
();
d
=
t
.
next
())
{
if
(
select
(
d
)
&&
!
vmarker
.
isMarked
(
d
))
{
vmarker
.
mark
(
d
);
if
(
select
(
d
))
bb
.
addPoint
(
position
[
d
])
;
}
}
return
bb
;
}
...
...
include/Algo/Geometry/normal.hpp
View file @
887aa340
...
...
@@ -25,6 +25,7 @@
#include "Algo/Geometry/basic.h"
#include "Algo/Geometry/area.h"
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
#include <cmath>
...
...
@@ -41,35 +42,26 @@ namespace Geometry
template
<
typename
PFP
>
typename
PFP
::
VEC3
triangleNormal
(
typename
PFP
::
MAP
&
map
,
Dart
d
,
const
typename
PFP
::
TVEC3
&
position
)
{
typedef
typename
PFP
::
VEC3
VEC3
;
const
VEC3
&
p1
=
position
[
d
];
const
VEC3
&
p2
=
position
[
map
.
phi1
(
d
)];
const
VEC3
&
p3
=
position
[
map
.
phi_1
(
d
)];
VEC3
N
=
Geom
::
triangleNormal
(
p1
,
p2
,
p3
)
;
typename
PFP
::
VEC3
N
=
Geom
::
triangleNormal
(
position
[
d
],
position
[
map
.
phi1
(
d
)],
position
[
map
.
phi_1
(
d
)])
;
N
.
normalize
()
;
return
N
;
}
template
<
typename
PFP
>
typename
PFP
::
VEC3
newellNormal
(
typename
PFP
::
MAP
&
map
,
Dart
d
,
const
typename
PFP
::
TVEC3
&
position
)
{
Dart
it
=
d
;
typename
PFP
::
VEC3
N
(
0
);
Traversor2FV
<
typename
PFP
::
MAP
>
t
(
map
,
d
)
;
do
for
(
Dart
it
=
t
.
begin
();
it
!=
t
.
end
();
it
=
t
.
next
())
{
const
typename
PFP
::
VEC3
&
P
=
position
[
it
];
it
=
map
.
phi1
(
it
);
const
typename
PFP
::
VEC3
&
Q
=
position
[
it
];
const
typename
PFP
::
VEC3
&
Q
=
position
[
map
.
phi1
(
it
)];
N
[
0
]
+=
(
P
[
1
]
-
Q
[
1
])
*
(
P
[
2
]
+
Q
[
2
]);
N
[
1
]
+=
(
P
[
2
]
-
Q
[
2
])
*
(
P
[
0
]
+
Q
[
0
]);
N
[
2
]
+=
(
P
[
0
]
-
Q
[
0
])
*
(
P
[
1
]
+
Q
[
1
]);
}
while
(
it
!=
d
);
}
N
.
normalize
();
return
N
;
}
...
...
@@ -77,25 +69,24 @@ typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename P
template
<
typename
PFP
>
typename
PFP
::
VEC3
faceNormal
(
typename
PFP
::
MAP
&
map
,
Dart
d
,
const
typename
PFP
::
TVEC3
&
position
)
{
typedef
typename
PFP
::
VEC3
VEC3
;
if
(
map
.
isFaceTriangle
(
d
))
return
triangleNormal
<
PFP
>
(
map
,
d
,
position
)
;
else
{
VEC3
N
(
0
)
;
Dart
it
=
d
;
do
{
VEC3
n
=
triangleNormal
<
PFP
>
(
map
,
it
,
position
)
;
//if(!std::isnan(n[0]) && !std::isnan(n[1]) && !std::isnan(n[2]))
if
(
!
n
.
hasNan
())
N
+=
n
;
it
=
map
.
phi1
(
it
)
;
}
while
(
it
!=
d
)
;
N
.
normalize
()
;
return
N
;
}
return
newellNormal
<
PFP
>
(
map
,
d
,
position
)
;
// {
// VEC3 N(0) ;
// Dart it = d ;
// do
// {
// VEC3 n = triangleNormal<PFP>(map, it, position) ;
// //if(!std::isnan(n[0]) && !std::isnan(n[1]) && !std::isnan(n[2]))
// if(!n.hasNan())
// N += n ;
// it = map.phi1(it) ;
// } while (it != d) ;
// N.normalize() ;
// return N ;
// }
}
template
<
typename
PFP
>
...
...
@@ -104,8 +95,9 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P
typedef
typename
PFP
::
VEC3
VEC3
;
VEC3
N
(
0
)
;
Dart
it
=
d
;
do
Traversor2VF
<
typename
PFP
::
MAP
>
t
(
map
,
d
)
;
for
(
Dart
it
=
t
.
begin
();
it
!=
t
.
end
();
it
=
t
.
next
())
{
VEC3
n
=
faceNormal
<
PFP
>
(
map
,
it
,
position
)
;
if
(
!
n
.
hasNan
())
...
...
@@ -115,8 +107,8 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P
n
*=
convexFaceArea
<
PFP
>
(
map
,
it
,
position
)
/
(
v1
.
norm2
()
*
v2
.
norm2
())
;
N
+=
n
;
}
it
=
map
.
phi1
(
map
.
phi2
(
it
))
;
}
while
(
it
!=
d
)
;
}
N
.
normalize
()
;
return
N
;
}
...
...
@@ -124,28 +116,22 @@ typename PFP::VEC3 vertexNormal(typename PFP::MAP& map, Dart d, const typename P
template
<
typename
PFP
>
void
computeNormalFaces
(
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
position
,
typename
PFP
::
TVEC3
&
face_normal
,
const
FunctorSelect
&
select
,
unsigned
int
thread
)
{
CellMarker
marker
(
map
,
FACE
,
thread
);
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
TraversorF
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
select
(
d
)
&&
!
marker
.
isMarked
(
d
))
{
marker
.
mark
(
d
);
if
(
select
(
d
))
face_normal
[
d
]
=
faceNormal
<
PFP
>
(
map
,
d
,
position
)
;
}
}
}
template
<
typename
PFP
>
void
computeNormalVertices
(
typename
PFP
::
MAP
&
map
,
const
typename
PFP
::
TVEC3
&
position
,
typename
PFP
::
TVEC3
&
normal
,
const
FunctorSelect
&
select
,
unsigned
int
thread
)
{
CellMarker
marker
(
map
,
VERTEX
,
thread
);
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
TraversorV
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
select
(
d
)
&&
!
marker
.
isMarked
(
d
))
{
marker
.
mark
(
d
);
if
(
select
(
d
))
normal
[
d
]
=
vertexNormal
<
PFP
>
(
map
,
d
,
position
)
;
}
}
}
...
...
@@ -155,8 +141,6 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart
typedef
typename
PFP
::
VEC3
VEC3
;
Dart
dd
=
map
.
phi2
(
d
)
;
if
(
dd
==
d
)
return
0
;
const
VEC3
n1
=
faceNormal
<
PFP
>
(
map
,
d
,
position
)
;
const
VEC3
n2
=
faceNormal
<
PFP
>
(
map
,
dd
,
position
)
;
...
...
@@ -165,6 +149,7 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart
typename
PFP
::
REAL
s
=
e
*
(
n1
^
n2
)
;
typename
PFP
::
REAL
c
=
n1
*
n2
;
typename
PFP
::
REAL
a
(
0
)
;
// the following trick is useful for avoiding NaNs (due to floating point errors)
if
(
c
>
0.5
)
a
=
asin
(
s
)
;
else
...
...
@@ -182,14 +167,11 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart
template
<
typename
PFP
>
void
computeAnglesBetweenNormalsOnEdges
(
typename
PFP
::
MAP
&
map
,
typename
PFP
::
TVEC3
&
position
,
typename
PFP
::
TREAL
&
angles
,
const
FunctorSelect
&
select
,
unsigned
int
thread
)
{
CellMarker
me
(
map
,
EDGE
,
thread
)
;
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
TraversorE
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
select
(
d
)
&&
!
me
.
isMarked
(
d
))
{
me
.
mark
(
d
)
;
if
(
select
(
d
))
angles
[
d
]
=
computeAngleBetweenNormalsOnEdge
<
PFP
>
(
map
,
d
,
position
)
;
}
}
}
...
...
include/Algo/Render/GL2/mapRender.hpp
View file @
887aa340
...
...
@@ -22,16 +22,16 @@
* *
*******************************************************************************/
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/cellmarker.h"
#include "Topology/generic/traversorCell.h"
#include "Utils/vbo.h"
#include "Topology/generic/attributeHandler.h"
#include "Geometry/intersection.h"
#include "Algo/Geometry/normal.h"
#include "Topology/generic/traversorCell.h"
namespace
CGoGN
{
...
...
@@ -44,7 +44,6 @@ namespace Render
namespace
GL2
{
inline
bool
MapRender
::
cmpVP
(
VertexPoly
*
lhs
,
VertexPoly
*
rhs
)
{
// return lhs->value < rhs->value;
...
...
@@ -54,7 +53,6 @@ inline bool MapRender::cmpVP(VertexPoly* lhs, VertexPoly* rhs)
return
lhs
->
value
<
rhs
->
value
;
}
template
<
typename
VEC3
>
bool
MapRender
::
inTriangle
(
const
VEC3
&
P
,
const
VEC3
&
normal
,
const
VEC3
&
Ta
,
const
VEC3
&
Tb
,
const
VEC3
&
Tc
)
{
...
...
@@ -72,8 +70,6 @@ bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, c
return
true
;
}
template
<
typename
PFP
>
void
MapRender
::
recompute2Ears
(
AttributeHandler
<
typename
PFP
::
VEC3
>&
position
,
VertexPoly
*
vp
,
const
typename
PFP
::
VEC3
&
normalPoly
,
VPMS
&
ears
,
bool
convex
)
{
...
...
@@ -136,7 +132,6 @@ void MapRender::recompute2Ears( AttributeHandler<typename PFP::VEC3>& position,
vp2
->
ear
=
ears
.
insert
(
vp2
);
}
template
<
typename
PFP
>
float
MapRender
::
computeEarAngle
(
const
typename
PFP
::
VEC3
&
P1
,
const
typename
PFP
::
VEC3
&
P2
,
const
typename
PFP
::
VEC3
&
P3
,
const
typename
PFP
::
VEC3
&
normalPoly
)
{
...
...
@@ -155,7 +150,6 @@ float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PF
return
dotpr
;
}
template
<
typename
PFP
>
bool
MapRender
::
computeEarIntersection
(
AttributeHandler
<
typename
PFP
::
VEC3
>&
position
,
VertexPoly
*
vp
,
const
typename
PFP
::
VEC3
&
normalPoly
)
{
...
...
@@ -180,8 +174,6 @@ bool MapRender::computeEarIntersection(AttributeHandler<typename PFP::VEC3>& pos
return
true
;
}
template
<
typename
PFP
>
inline
void
MapRender
::
addEarTri
(
typename
PFP
::
MAP
&
map
,
Dart
d
,
std
::
vector
<
GLuint
>&
tableIndices
)
{
...
...
@@ -287,7 +279,6 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
}
}
template
<
typename
PFP
>
inline
void
MapRender
::
addTri
(
typename
PFP
::
MAP
&
map
,
Dart
d
,
std
::
vector
<
GLuint
>&
tableIndices
)
{
...
...
@@ -317,15 +308,13 @@ inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint
}
template
<
typename
PFP
>
void
MapRender
::
initTriangles
(
typename
PFP
::
MAP
&
map
,
const
FunctorSelect
&
good
,
std
::
vector
<
GLuint
>&
tableIndices
,
unsigned
int
thread
)
{
// DartMarker m(map, thread);
tableIndices
.
reserve
(
4
*
map
.
getNbDarts
()
/
3
);
TraversorF
<
typename
PFP
::
MAP
>
trav
(
map
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
TraversorF
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
good
(
d
))
addTri
<
PFP
>
(
map
,
d
,
tableIndices
);
...
...
@@ -391,23 +380,12 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele
template
<
typename
PFP
>
void
MapRender
::
initLines
(
typename
PFP
::
MAP
&
map
,
const
FunctorSelect
&
good
,
std
::
vector
<
GLuint
>&
tableIndices
,
unsigned
int
thread
)
{
// DartMarker m(map, thread);
tableIndices
.
reserve
(
map
.
getNbDarts
());
// for(Dart d = map.begin(); d != map.end(); map.next(d))
// {
// if(!m.isMarked(d) && good(d))
// {
// tableIndices.push_back(map.getEmbedding(VERTEX, d));
// tableIndices.push_back(map.getEmbedding(VERTEX, map.phi1(d)));
// m.markOrbit(EDGE, d);
// }
// }
TraversorE
<
typename
PFP
::
MAP
>
trav
(
map
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
TraversorE
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
good
(
d
)
&&
map
.
isBoundaryEdge
(
d
)
)
if
(
good
(
d
))
{
tableIndices
.
push_back
(
map
.
getEmbedding
(
VERTEX
,
d
));
tableIndices
.
push_back
(
map
.
getEmbedding
(
VERTEX
,
map
.
phi1
(
d
)));
...
...
@@ -418,10 +396,10 @@ void MapRender::initLines(typename PFP::MAP& map, const FunctorSelect& good, std
template
<
typename
PFP
>
void
MapRender
::
initBoundaries
(
typename
PFP
::
MAP
&
map
,
const
FunctorSelect
&
good
,
std
::
vector
<
GLuint
>&
tableIndices
,
unsigned
int
thread
)
{
TraversorE
<
typename
PFP
::
MAP
>
trav
(
map
);
tableIndices
.
reserve
(
map
.
getNbDarts
());
//TODO optimisation ?
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
TraversorE
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
good
(
d
)
&&
map
.
isBoundaryEdge
(
d
))
{
...
...
@@ -483,21 +461,16 @@ void MapRender::initLinesOptimized(typename PFP::MAP& map, const FunctorSelect&
template
<
typename
PFP
>
void
MapRender
::
initPoints
(
typename
PFP
::
MAP
&
map
,
const
FunctorSelect
&
good
,
std
::
vector
<
GLuint
>&
tableIndices
,
unsigned
int
thread
)
{
CellMarker
m
(
map
,
VERTEX
,
thread
)
;
tableIndices
.
reserve
(
map
.
getNbDarts
()
/
5
);
for
(
Dart
d
=
map
.
begin
();
d
!=
map
.
end
();
map
.
next
(
d
))
TraversorV
<
typename
PFP
::
MAP
>
trav
(
map
,
thread
);
for
(
Dart
d
=
trav
.
begin
();
d
!=
trav
.
end
();
d
=
trav
.
next
())
{
if
(
!
m
.
isMarked
(
d
)
&&
good
(
d
))
{
if
(
good
(
d
))
tableIndices
.
push_back
(
map
.
getEmbedding
(
VERTEX
,
d
));
m
.
mark
(
d
)
;
}
}
}
template
<
typename
PFP
>
void
MapRender
::
initPrimitives
(
typename
PFP
::
MAP
&
map
,
const
FunctorSelect
&
good
,
int
prim
,
bool
optimized
,
unsigned
int
thread
)
{
...
...
include/Topology/generic/traversor2.h
View file @
887aa340
...
...
@@ -81,7 +81,7 @@ public:
if
(
current
!=
NIL
)
{
current
=
m
.
alpha1
(
current
)
;
if
(
m
.
isBoundary
m
arked
(
current
))
// jump over a boundary face
if
(
m
.
isBoundary
M
arked
(
current
))
// jump over a boundary face
current
=
m
.
alpha1
(
current
)
;
if
(
current
==
start
)
current
=
NIL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment