MOAB: Mesh Oriented datABase
(version 5.5.0)
read_obj_test.cpp
Go to the documentation of this file.
1
#include <iostream>
2
#include "
moab/Interface.hpp
"
3
#include "
TestUtil.hpp
"
4
#include "
Internals.hpp
"
5
#include "
moab/Core.hpp
"
6
#include "
MBTagConventions.hpp
"
7
#include "
moab/Types.hpp
"
8
#include "
moab/GeomTopoTool.hpp
"
9
10
using namespace
moab
;
11
12
#define CHKERR( A ) \
13
do \
14
{ \
15
if( MB_SUCCESS != ( A ) ) \
16
{ \
17
std::cerr << "Failure (error code "
<< ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
18
return A; \
19
} \
20
} while( false )
21
22
std::string
test
= TestDir +
"unittest/io/test.obj"
;
23
std::string
shuttle
= TestDir +
"unittest/io/shuttle.obj"
;
24
25
GeomTopoTool
*
myGeomTool
;
26
27
Tag
geom_tag
;
28
Tag
name_tag
;
29
Tag
id_tag
;
30
31
void
read_file
(
Interface
&
moab
,
const
char
*
input_file
);
32
void
test_check_num_entities
();
33
void
test_check_meshsets
();
34
void
test_check_groups
();
35
36
int
main
()
37
{
38
int
result = 0;
39
40
result +=
RUN_TEST
(
test_check_num_entities
);
41
result +=
RUN_TEST
(
test_check_meshsets
);
42
result +=
RUN_TEST
(
test_check_groups
);
43
44
return
result;
45
}
46
47
void
read_file
(
Interface
&
moab
,
const
char
*
input_file
)
48
{
49
ErrorCode
rval =
moab
.load_file(
input_file
);
CHECK_ERR
( rval );
50
}
51
52
void
test_check_num_entities
()
53
{
54
ErrorCode
rval;
55
Core
core;
56
Interface
* mbi = &core;
57
read_file
( core,
test
.c_str() );
58
59
// check that number of verts created is 7
60
Range
verts;
61
int
vert_dim = 0;
62
rval = mbi->
get_entities_by_dimension
( 0, vert_dim, verts );
CHECK_ERR
( rval );
63
CHECK_EQUAL
( 7, (
int
)verts.
size
() );
64
65
// check that number of tris created is 3
66
Range
tris;
67
int
tri_dim = 2;
68
rval = mbi->
get_entities_by_dimension
( 0, tri_dim, tris );
CHECK_ERR
( rval );
69
CHECK_EQUAL
( 3, (
int
)tris.
size
() );
70
}
71
72
void
test_check_meshsets
()
73
{
74
ErrorCode
rval;
75
Core
core;
76
Interface
* mbi = &core;
77
read_file
( core,
test
.c_str() );
78
79
myGeomTool
=
new
GeomTopoTool
( mbi );
80
81
Range
ent_sets;
82
rval = mbi->
tag_get_handle
(
GEOM_DIMENSION_TAG_NAME
, 1,
MB_TYPE_INTEGER
,
geom_tag
);
CHECK_ERR
( rval );
83
rval = mbi->
get_entities_by_type_and_tag
( 0,
MBENTITYSET
, &
geom_tag
, NULL, 1, ent_sets );
CHECK_ERR
( rval );
84
85
Range::iterator
it;
86
Range
parents,
children
;
87
int
sense;
88
int
dim
, num_surfs = 0, num_vols = 0;
89
90
for
( it = ent_sets.
begin
(); it != ent_sets.
end
(); ++it )
91
{
92
rval = mbi->
tag_get_data
(
geom_tag
, &( *it ), 1, &
dim
);
93
94
if
(
dim
== 2 )
95
{
96
num_surfs++;
97
98
// check that one parent is created for each surface
99
parents.
clear
();
100
rval = mbi->
get_parent_meshsets
( *it, parents );
CHECK_ERR
( rval );
101
CHECK_EQUAL
( 1, (
int
)parents.
size
() );
102
103
// check that sense of surface wrt parent is FORWARD = 1
104
rval =
myGeomTool
->
get_sense
( *it, *parents.
begin
(), sense );
CHECK_ERR
( rval );
105
CHECK_EQUAL
( 1, sense );
106
}
107
else
if
(
dim
== 3 )
108
{
109
num_vols++;
110
111
// check that one child is created for each volume
112
children
.clear();
113
rval = mbi->
get_child_meshsets
( *it,
children
);
CHECK_ERR
( rval );
114
CHECK_EQUAL
( 1, (
int
)
children
.size() );
115
}
116
}
117
118
// check that two surfaces and two volumes are created
119
CHECK_EQUAL
( 2, num_surfs );
120
CHECK_EQUAL
( 2, num_vols );
121
122
delete
myGeomTool
;
123
}
124
125
void
test_check_groups
()
126
{
127
ErrorCode
rval;
128
Core
core;
129
Interface
* mbi = &core;
130
read_file
( core,
shuttle
.c_str() );
131
132
// check that number of tris created is 616
133
// 170 tris + 223 quads split into 2 tris = 616
134
Range
tris;
135
int
tri_dim = 2;
136
rval = mbi->
get_entities_by_dimension
( 0, tri_dim, tris );
CHECK_ERR
( rval );
137
CHECK_EQUAL
( 616, (
int
)tris.
size
() );
138
139
// check that 11 mesh sets are created
140
// 1 for global vert set + 1 for each of 10 groups
141
Range
ent_sets, mesh_sets;
142
id_tag
= mbi->
globalId_tag
();
143
rval = mbi->
get_entities_by_type_and_tag
( 0,
MBENTITYSET
, &
id_tag
, NULL, 1, ent_sets );
144
145
CHECK_EQUAL
( 11, (
int
)ent_sets.
size
() );
146
}
test
io
read_obj_test.cpp
Generated on Wed Oct 4 2023 14:20:31 for MOAB: Mesh Oriented datABase by
1.9.1