Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
extraction_informations_forme_3D
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Astrid Beyer
extraction_informations_forme_3D
Commits
996f0012
Commit
996f0012
authored
2 years ago
by
Astrid Beyer
Browse files
Options
Downloads
Patches
Plain Diff
lecteur OFF
parent
0d67000b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
vtkOFFReader.cxx
+188
-0
188 additions, 0 deletions
vtkOFFReader.cxx
vtkOFFReader.h
+47
-0
47 additions, 0 deletions
vtkOFFReader.h
with
236 additions
and
1 deletion
CMakeLists.txt
+
1
−
1
View file @
996f0012
...
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 11)
...
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 11)
find_package
(
TTKVTK REQUIRED
)
find_package
(
TTKVTK REQUIRED
)
add_executable
(
projet-stage main.cpp triangulate.cpp
)
add_executable
(
projet-stage main.cpp triangulate.cpp
vtkOFFReader.cxx
)
target_link_libraries
(
projet-stage
target_link_libraries
(
projet-stage
PUBLIC
PUBLIC
...
...
This diff is collapsed.
Click to expand it.
vtkOFFReader.cxx
0 → 100644
+
188
−
0
View file @
996f0012
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkOFFReader.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include
"vtkOFFReader.h"
#include
"vtkCellArray.h"
#include
"vtkFloatArray.h"
#include
"vtkInformation.h"
#include
"vtkInformationVector.h"
#include
"vtkObjectFactory.h"
#include
"vtkPointData.h"
#include
"vtkPolyData.h"
#include
"vtkTriangle.h"
#include
<sstream>
#include
<fstream>
vtkStandardNewMacro
(
vtkOFFReader
);
// Description:
// Instantiate object with NULL filename.
vtkOFFReader
::
vtkOFFReader
()
{
this
->
FileName
=
NULL
;
this
->
SetNumberOfInputPorts
(
0
);
}
vtkOFFReader
::~
vtkOFFReader
()
{
if
(
this
->
FileName
)
{
delete
[]
this
->
FileName
;
this
->
FileName
=
NULL
;
}
}
/*--------------------------------------------------------
This is only partial support for the OFF format, which is
quite complicated. To find a full specification,
search the net for "OFF format", eg.:
http://people.sc.fsu.edu/~burkardt/data/off/off.html
We support only vertices and faces composed of 3 vertices.
---------------------------------------------------------*/
// a replacement for isspace()
int
is_whitespace
(
char
c
)
{
if
(
c
==
' '
||
c
==
'\t'
||
c
==
'\n'
||
c
==
'\r'
||
c
==
'\v'
||
c
==
'\f'
)
return
1
;
else
return
0
;
}
int
vtkOFFReader
::
RequestData
(
vtkInformation
*
vtkNotUsed
(
request
),
vtkInformationVector
**
vtkNotUsed
(
inputVector
),
vtkInformationVector
*
outputVector
)
{
// get the info object
vtkInformation
*
outInfo
=
outputVector
->
GetInformationObject
(
0
);
// get the ouptut
vtkPolyData
*
output
=
vtkPolyData
::
SafeDownCast
(
outInfo
->
Get
(
vtkDataObject
::
DATA_OBJECT
()));
if
(
!
this
->
FileName
)
{
vtkErrorMacro
(
<<
"A FileName must be specified."
);
return
0
;
}
std
::
ifstream
in
(
this
->
FileName
);
if
(
!
in
)
{
vtkErrorMacro
(
<<
"File "
<<
this
->
FileName
<<
" not found"
);
return
0
;
}
vtkDebugMacro
(
<<
"Reading file"
);
// intialise some structures to store the file contents in
vtkPoints
*
points
=
vtkPoints
::
New
();
vtkCellArray
*
polys
=
vtkCellArray
::
New
();
// -- work through the file line by line, assigning into the above structures as appropriate --
float
xyz
[
3
];
std
::
string
line
;
getline
(
in
,
line
);
// throw the 1st line away, it always says "OFF"
// Read until we get to the first line that is not a comment or a blank line.
// This line second states the number of vertices, faces, and edges.
while
(
getline
(
in
,
line
))
{
// std::cout << line << std::endl;
if
(
line
.
size
()
==
0
)
continue
;
if
(
line
[
0
]
==
'#'
)
continue
;
// if we get to here, this is the info line
break
;
}
// std::cout << "Found info line." << std::endl;
// At this point, the line were are interested in is stored in 'line'
// We are only interested in vertices and faces.
std
::
stringstream
ss
;
ss
<<
line
;
unsigned
int
NumberOfVertices
,
NumberOfFaces
;
ss
>>
NumberOfVertices
>>
NumberOfFaces
;
// std::cout << "Vertices: " << NumberOfVertices << " Faces: " << NumberOfFaces << std::endl;
// Now we can start to read the vertices
unsigned
int
VertexCounter
=
0
;
while
(
getline
(
in
,
line
)
&&
VertexCounter
<
NumberOfVertices
)
{
if
(
line
.
size
()
==
0
)
// skip blank lines (they should only occur before the vertices start)
continue
;
std
::
stringstream
ssVertex
;
ssVertex
<<
line
;
float
x
,
y
,
z
;
ssVertex
>>
x
>>
y
>>
z
;
points
->
InsertNextPoint
(
x
,
y
,
z
);
// std::cout << "adding vertex: " << x << " " << y << " " << z << std::endl;
VertexCounter
++
;
}
// (end of vertex while loop)
unsigned
int
FaceCounter
=
0
;
// read faces
do
{
std
::
stringstream
ssFace
;
ssFace
<<
line
;
unsigned
int
NumFaceVerts
,
Vert0
,
Vert1
,
Vert2
;
ssFace
>>
NumFaceVerts
>>
Vert0
>>
Vert1
>>
Vert2
;
if
(
NumFaceVerts
!=
3
)
{
vtkErrorMacro
(
<<
"File "
<<
this
->
FileName
<<
" contains a face with >3 ("
<<
NumFaceVerts
<<
") vertices."
);
return
0
;
}
// std::cout << "adding triangle: " << Vert0 << " " << Vert1 << " " << Vert2 << std::endl;
vtkTriangle
*
triangle
=
vtkTriangle
::
New
();
triangle
->
GetPointIds
()
->
SetId
(
0
,
Vert0
);
triangle
->
GetPointIds
()
->
SetId
(
1
,
Vert1
);
triangle
->
GetPointIds
()
->
SetId
(
2
,
Vert2
);
polys
->
InsertNextCell
(
triangle
);
triangle
->
Delete
();
FaceCounter
++
;
}
while
(
getline
(
in
,
line
)
&&
FaceCounter
<
NumberOfFaces
);
// we have finished with the file
in
.
close
();
output
->
SetPoints
(
points
);
output
->
SetPolys
(
polys
);
points
->
Delete
();
polys
->
Delete
();
return
1
;
}
void
vtkOFFReader
::
PrintSelf
(
ostream
&
os
,
vtkIndent
indent
)
{
this
->
Superclass
::
PrintSelf
(
os
,
indent
);
os
<<
indent
<<
"File Name: "
<<
(
this
->
FileName
?
this
->
FileName
:
"(none)"
)
<<
"
\n
"
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
vtkOFFReader.h
0 → 100644
+
47
−
0
View file @
996f0012
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkOFFReader.h,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkOFFReader - read .off files
// .SECTION Description
// vtkOFFReader is a source object that reads .off
// files. The output of this source object is polygonal data.
// .SECTION See Also
#ifndef __vtkOFFReader_h
#define __vtkOFFReader_h
#include
"vtkPolyDataAlgorithm.h"
class
vtkOFFReader
:
public
vtkPolyDataAlgorithm
{
public:
static
vtkOFFReader
*
New
();
vtkTypeMacro
(
vtkOFFReader
,
vtkPolyDataAlgorithm
);
void
PrintSelf
(
ostream
&
os
,
vtkIndent
indent
);
// Description:
// Specify file name of .off file.
vtkSetStringMacro
(
FileName
);
vtkGetStringMacro
(
FileName
);
protected:
vtkOFFReader
();
~
vtkOFFReader
();
int
RequestData
(
vtkInformation
*
,
vtkInformationVector
**
,
vtkInformationVector
*
);
char
*
FileName
;
private:
vtkOFFReader
(
const
vtkOFFReader
&
);
// Not implemented.
void
operator
=
(
const
vtkOFFReader
&
);
// Not implemented.
};
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment