Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenFlipper-Free
OpenFlipper-Free
Commits
12a46ee4
Commit
12a46ee4
authored
Nov 25, 2016
by
Christopher Tenter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use PolyLineNode in PolyLineCollection (WIP)
parent
0365df71
Pipeline
#3738
passed with stage
in 47 minutes and 57 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
44 deletions
+98
-44
ObjectTypes/PolyLineCollection/PolyLineCollectionNodeT.cc
ObjectTypes/PolyLineCollection/PolyLineCollectionNodeT.cc
+90
-34
ObjectTypes/PolyLineCollection/PolyLineCollectionNodeT.hh
ObjectTypes/PolyLineCollection/PolyLineCollectionNodeT.hh
+8
-10
No files found.
ObjectTypes/PolyLineCollection/PolyLineCollectionNodeT.cc
View file @
12a46ee4
...
...
@@ -97,6 +97,15 @@ PolyLineCollectionNodeT<PolyLineCollection>::PolyLineCollectionNodeT(PolyLineCol
//----------------------------------------------------------------------------
template
<
class
PolyLineCollection
>
PolyLineCollectionNodeT
<
PolyLineCollection
>::~
PolyLineCollectionNodeT
()
{
for
(
size_t
i
=
0
;
i
<
polylineNodes_
.
size
();
++
i
)
delete
polylineNodes_
[
i
];
}
//----------------------------------------------------------------------------
template
<
class
PolyLineCollection
>
void
PolyLineCollectionNodeT
<
PolyLineCollection
>::
...
...
@@ -354,57 +363,104 @@ updateVBO() {
if
(
lines_did_change
){
// Update the vertex declaration based on the input data:
vertexDecl_
.
clear
();
//
We always output vertex positions
vertexDecl_
.
addElement
(
GL_FLOAT
,
3
,
ACG
::
VERTEX_USAGE_POSITION
);
//
update internal line node
// these are used exclusively used to fill the vertex buffer
// size in bytes of vbo, create additional vertex for closed loop indexing
unsigned
int
bufferSize
=
vertexDecl_
.
getVertexStride
()
*
offset
;
// Create the required array
char
*
vboData_
=
new
char
[
bufferSize
]
;
size_t
prevLineCount
=
polylineNodes_
.
size
();
size_t
curLineCount
=
polyline_collection_
.
n_polylines
()
;
for
(
typename
PolyLineCollection
::
iterator
it
=
polyline_collection_
.
iter
();
it
;
++
it
){
typename
PolyLineCollection
::
PolyLine
*
polyline
=
*
it
;
if
(
polyline
&&
polyline
->
n_vertices
()
>
0
){
size_t
offset
=
offsets_
[
it
.
idx
()].
first
;
for
(
unsigned
int
i
=
0
;
i
<
polyline
->
n_vertices
();
++
i
)
{
writeVertex
(
polyline
,
i
,
vboData_
+
(
offset
+
i
)
*
vertexDecl_
.
getVertexStride
());
}
// free memory for removed lines
if
(
curLineCount
<
prevLineCount
)
{
for
(
size_t
i
=
curLineCount
;
i
<
prevLineCount
;
++
i
)
delete
polylineNodes_
[
i
];
}
// First point is added to the end for a closed loop
writeVertex
(
polyline
,
0
,
vboData_
+
(
offset
+
polyline
->
n_vertices
())
*
vertexDecl_
.
getVertexStride
());
}
polylineNodes_
.
resize
(
curLineCount
);
for
(
size_t
i
=
0
;
i
<
curLineCount
;
++
i
)
{
typename
PolyLineCollection
::
PolyLine
*
polyline
=
polyline_collection_
.
polyline
(
i
);
polylineNodes_
[
i
]
=
new
PolyLineNodeT
<
typename
PolyLineCollection
::
PolyLine
>
(
*
polyline
);
}
// Update the vertex declaration based on the input data:
vertexDecl_
.
clear
();
vertexDeclVColor_
.
clear
();
vertexDeclEColor_
.
clear
();
if
(
curLineCount
>
0
)
{
polylineNodes_
[
0
]
->
setupVertexDeclaration
(
&
vertexDecl_
,
0
);
polylineNodes_
[
0
]
->
setupVertexDeclaration
(
&
vertexDecl_
,
1
);
polylineNodes_
[
0
]
->
setupVertexDeclaration
(
&
vertexDecl_
,
2
);
// make sure that all polylines have the same vertex format
bool
equalVertexFormat
=
true
;
for
(
size_t
i
=
1
;
i
<
curLineCount
;
++
i
)
{
VertexDeclaration
decl
[
3
];
for
(
int
k
=
0
;
k
<
3
;
++
k
)
polylineNodes_
[
i
]
->
setupVertexDeclaration
(
&
decl
[
k
],
k
);
if
(
decl
[
0
]
!=
vertexDecl_
||
decl
[
1
]
!=
vertexDeclVColor_
||
decl
[
2
]
!=
vertexDeclEColor_
)
equalVertexFormat
=
false
;
}
// Move data to the buffer in gpu memory
vbo_
.
upload
(
bufferSize
,
vboData_
,
GL_STATIC_DRAW
);
vbo_
.
unbind
();
// Remove the local storage
delete
[]
vboData_
;
}
if
(
!
equalVertexFormat
)
std
::
cerr
<<
"PolyLineCollection error: polylines do not have the same vertex format, so the collection vbo could not be created"
<<
std
::
endl
;
else
{
//
Update done.
updateVBO_
=
false
;
}
//
size in bytes of vbo, create additional vertex for closed loop indexing
size_t
stride
=
vertexDecl_
.
getVertexStride
()
;
size_t
bufferSize
=
stride
*
offset
;
if
(
bufferSize
>
0
)
{
std
::
vector
<
char
>
vboData
(
bufferSize
);
//----------------------------------------------------------------------------
template
<
class
PolyLineCollection
>
void
PolyLineCollectionNodeT
<
PolyLineCollection
>::
writeVertex
(
typename
PolyLineCollection
::
PolyLine
*
_polyline
,
unsigned
int
_vertex
,
void
*
_dst
)
{
for
(
size_t
i
=
0
;
i
<
curLineCount
;
++
i
)
{
typename
PolyLineCollection
::
PolyLine
*
polyline
=
polyline_collection_
.
polyline
(
i
);
if
(
polyline
&&
polylineNodes_
[
i
]
&&
polyline
->
n_vertices
()
>
0
)
{
size_t
offset
=
offsets_
[
i
].
first
;
polylineNodes_
[
i
]
->
fillVertexBuffer
(
&
vboData
[(
offset
)
*
stride
],
bufferSize
,
true
);
}
ACG
::
Vec3f
&
pos
=
*
((
ACG
::
Vec3f
*
)
_dst
);
}
// Move data to the buffer in gpu memory
vbo_
.
upload
(
bufferSize
,
&
vboData
[
0
],
GL_STATIC_DRAW
);
vbo_
.
unbind
();
}
pos
=
OpenMesh
::
vector_cast
<
ACG
::
Vec3f
>
(
_polyline
->
point
(
_vertex
));
}
}
}
// Update done.
updateVBO_
=
false
;
}
//----------------------------------------------------------------------------
template
<
class
PolyLineCollection
>
...
...
ObjectTypes/PolyLineCollection/PolyLineCollectionNodeT.hh
View file @
12a46ee4
...
...
@@ -90,7 +90,7 @@ public:
PolyLineCollectionNodeT
(
PolyLineCollection
&
_pl
,
BaseNode
*
_parent
=
0
,
std
::
string
_name
=
"<PolyLineCollectionNode>"
);
/// Destructor
virtual
~
PolyLineCollectionNodeT
()
{}
virtual
~
PolyLineCollectionNodeT
()
;
PolyLineCollection
&
polyline_collection
()
{
return
polyline_collection_
;
}
...
...
@@ -131,7 +131,9 @@ private:
PolyLineCollectionNodeT
&
operator
=
(
const
PolyLineCollectionNodeT
&
_rhs
);
/// Buffer organization
ACG
::
VertexDeclaration
vertexDecl_
;
ACG
::
VertexDeclaration
vertexDecl_
;
// layout without colors
ACG
::
VertexDeclaration
vertexDeclVColor_
;
// layout with vertex colors
ACG
::
VertexDeclaration
vertexDeclEColor_
;
// layout with edge colors
/** \brief Trigger an update of the vbo
*
...
...
@@ -140,13 +142,6 @@ private:
*/
void
updateVBO
();
/** \brief Write vertex data for rendering to a buffer
*
* @param _vertex index of polyline vertex
* @param _dst address of vertex in buffer
*/
void
writeVertex
(
typename
PolyLineCollection
::
PolyLine
*
_polyline
,
unsigned
int
_vertex
,
void
*
_dst
);
private:
/// The associated poly line collection
...
...
@@ -155,6 +150,9 @@ private:
/// VBO used to render the poly line
GeometryBuffer
vbo_
;
/// IBO used to render in line mode
IndexBuffer
ibo_
;
/// Flag to trigger update of vbo
bool
updateVBO_
;
...
...
@@ -163,7 +161,7 @@ private:
std
::
vector
<
std
::
pair
<
size_t
,
size_t
>
>
offsets_
;
std
::
vector
<
PolyLineNodeT
<
typename
PolyLineCollection
::
PolyLine
>
>
polylineNodes_
;
std
::
vector
<
PolyLineNodeT
<
typename
PolyLineCollection
::
PolyLine
>
*
>
polylineNodes_
;
size_t
total_vertex_count_
;
};
...
...
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