Skip to content

Commit d6d3333

Browse files
committed
- Correct calculation of normals
- More verbosity for geometry conversion settings
1 parent 5ef06dc commit d6d3333

File tree

6 files changed

+49
-48
lines changed

6 files changed

+49
-48
lines changed

src/ifcgeom/IfcGeomObjects.cpp

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "../ifcgeom/IfcGeom.h"
4747

4848
// Welds vertices that belong to different faces
49-
bool weld_vertices = false;
49+
bool weld_vertices = true;
5050

5151
int IfcGeomObjects::IfcMesh::addvert(const gp_XYZ& p) {
5252
const float X = (float)p.X();const float Y = (float)p.Y();const float Z = (float)p.Z();
@@ -93,9 +93,7 @@ IfcGeomObjects::IfcMesh::IfcMesh(int i, const IfcGeom::ShapeList& shapes) {
9393
if ( ! tri.IsNull() ) {
9494

9595
// A 3x3 matrix to rotate the vertex normals
96-
const gp_Mat rotation_matrix = use_world_coords
97-
? trsf.VectorialPart() * loc.Transformation().VectorialPart()
98-
: loc.Transformation().VectorialPart();
96+
const gp_Mat rotation_matrix = trsf.VectorialPart();
9997

10098
// Keep track of the number of times an edge is used
10199
// Manifold edges (i.e. edges used twice) are deemed invisible
@@ -431,14 +429,10 @@ const IfcGeomObjects::IfcObject* IfcGeomObjects::GetObject(int id) {
431429
const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() {
432430
return current_geom_obj;
433431
}
434-
bool IfcGeomObjects::Init(const char* fn, bool world_coords) {
435-
return IfcGeomObjects::Init(fn, world_coords, 0, 0);
432+
bool IfcGeomObjects::Init(const char* fn) {
433+
return IfcGeomObjects::Init(fn, 0, 0);
436434
}
437-
bool IfcGeomObjects::Init(const char* fn, bool world_coords, std::ostream* log1, std::ostream* log2) {
438-
Ifc::SetOutput(log1,log2);
439-
use_world_coords = world_coords;
440-
if ( !Ifc::Init(fn) ) return false;
441-
435+
bool _Init() {
442436
shapereps = Ifc::EntitiesByType<Ifc2x3::IfcShapeRepresentation>();
443437
if ( ! shapereps ) return false;
444438

@@ -452,42 +446,30 @@ bool IfcGeomObjects::Init(const char* fn, bool world_coords, std::ostream* log1,
452446
total = shapereps->Size();
453447
return true;
454448
}
455-
bool IfcGeomObjects::Init(std::istream& f, int len, bool world_coords, std::ostream* log1, std::ostream* log2) {
449+
bool IfcGeomObjects::Init(const char* fn, std::ostream* log1, std::ostream* log2) {
450+
Ifc::SetOutput(log1,log2);
451+
if ( !Ifc::Init(fn) ) return false;
452+
return _Init();
453+
}
454+
bool IfcGeomObjects::Init(std::istream& f, int len, std::ostream* log1, std::ostream* log2) {
456455
Ifc::SetOutput(log1,log2);
457-
use_world_coords = world_coords;
458456
if ( !Ifc::Init(f, len) ) return false;
459-
460-
shapereps = Ifc::EntitiesByType<Ifc2x3::IfcShapeRepresentation>();
461-
if ( ! shapereps ) return false;
462-
463-
outer = shapereps->begin();
464-
entities.reset();
465-
current_geom_obj = _get();
466-
467-
if ( ! current_geom_obj ) return false;
468-
469-
done = 0;
470-
total = shapereps->Size();
471-
return true;
457+
return _Init();
472458
}
473459
bool IfcGeomObjects::Init(void* data, int len) {
474460
Ifc::SetOutput(0,0);
475-
use_world_coords = true;
476-
weld_vertices = false;
477461
if ( !Ifc::Init(data, len) ) return false;
478-
479-
shapereps = Ifc::EntitiesByType<Ifc2x3::IfcShapeRepresentation>();
480-
if ( ! shapereps ) return false;
481-
482-
outer = shapereps->begin();
483-
entities.reset();
484-
current_geom_obj = _get();
485-
486-
if ( ! current_geom_obj ) return false;
487-
488-
done = 0;
489-
total = shapereps->Size();
490-
return true;
462+
return _Init();
463+
}
464+
void IfcGeomObjects::Settings(int setting, bool value) {
465+
switch ( setting ) {
466+
case USE_WORLD_COORDS:
467+
use_world_coords = value;
468+
break;
469+
case WELD_VERTICES:
470+
weld_vertices = value;
471+
break;
472+
}
491473
}
492474
int IfcGeomObjects::Progress() {
493475
return 100 * done / total;

src/ifcgeom/IfcGeomObjects.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868

6969
namespace IfcGeomObjects {
7070

71+
const int WELD_VERTICES = 1;
72+
const int USE_WORLD_COORDS = 2;
73+
7174
typedef std::vector<int>::const_iterator IntIt;
7275
typedef std::vector<float>::const_iterator FltIt;
7376
typedef std::pair< float,std::pair<float,float> > VertKey;
@@ -111,10 +114,11 @@ namespace IfcGeomObjects {
111114
IfcGeomObject(int my_id, int p_id, const std::string& n, const std::string& t, const std::string& g, const gp_Trsf& trsf, IfcMesh* m);
112115
};
113116

114-
bool Init(const char* fn, bool world_coords = false);
115-
bool Init(const char* fn, bool world_coords = false, std::ostream* log1= 0, std::ostream* log2= 0);
116-
bool Init(std::istream& f, int len, bool world_coords = false, std::ostream* log1= 0, std::ostream* log2= 0);
117+
bool Init(const char* fn);
117118
bool Init(void* data, int len);
119+
bool Init(const char* fn, std::ostream* log1= 0, std::ostream* log2= 0);
120+
bool Init(std::istream& f, int len, std::ostream* log1= 0, std::ostream* log2= 0);
121+
void Settings(int setting, bool value);
118122
bool CleanUp();
119123
const IfcGeomObject* Get();
120124
bool Next();

src/ifcjni/IfcJni.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ JNIEXPORT jobject JNICALL Java_org_ifcopenshell_IfcOpenShellModel_getGeometry (J
4343

4444
jintArray indices = env->NewIntArray(o->mesh->faces.size());
4545
jfloatArray positions = env->NewFloatArray(o->mesh->verts.size());
46-
jfloatArray normals = env->NewFloatArray(o->mesh->verts.size());
46+
jfloatArray normals = env->NewFloatArray(o->mesh->normals.size());
4747

4848
env->SetIntArrayRegion(indices,0,o->mesh->faces.size(),(jint*) &o->mesh->faces[0]);
4949
env->SetFloatArrayRegion(positions,0,o->mesh->verts.size(),(jfloat*) &o->mesh->verts[0]);
50+
env->SetFloatArrayRegion(normals,0,o->mesh->normals.size(),(jfloat*) &o->mesh->normals[0]);
5051

5152
jobject return_obj = env->NewObject(class_def, jconstructor, name, type, guid, indices, positions, normals);
5253

@@ -68,5 +69,7 @@ JNIEXPORT bool JNICALL Java_org_ifcopenshell_IfcOpenShellModel_setIfcData (JNIEn
6869
void* data = env->GetByteArrayElements(jdata, NULL);
6970
const int length = env->GetArrayLength(jdata);
7071
if ( ! data || ! length ) return false;
72+
IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true);
73+
IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false);
7174
return has_more = IfcGeomObjects::Init(data,length);
7275
}

src/ifcmax/IfcMax.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc,
109109

110110
itfc->ProgressStart("Importing file...", TRUE, fn, NULL);
111111

112-
if ( ! IfcGeomObjects::Init((char*)name,false,0,0) ) return false;
112+
IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,false);
113+
IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,true);
114+
115+
if ( ! IfcGeomObjects::Init((char*)name,0,0) ) return false;
113116

114117
std::map<int, TriObject*> dict;
115118
MtlBaseLib* mats = itfc->GetSceneMtls();

src/ifcobj/IfcObj.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ int main ( int argc, char** argv ) {
4747
return 1;
4848
}
4949

50+
IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true);
51+
IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false);
52+
5053
// Stream for log messages, we don't want to interupt our new progress bar...
5154
std::stringstream ss;
5255

5356
// Parse the file supplied in argv[1]. Returns true on succes.
5457
// The second argument defines whether geometry will be defined using global or local coordinates.
55-
if ( ! IfcGeomObjects::Init(argv[1],true,&std::cout,&ss) ) {
58+
if ( ! IfcGeomObjects::Init(argv[1],&std::cout,&ss) ) {
5659
std::cout << "[Error] unable to parse .ifc file or no geometrical entities found" << std::endl;
5760
return 1;
5861
}

src/ifcwrap/Interface.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
********************************************************************************/
1919

2020
namespace IfcGeomObjects {
21+
22+
const int WELD_VERTICES = 1;
23+
const int USE_WORLD_COORDS = 2;
24+
2125
class IfcMesh {
2226
public:
2327
int id;
2428
std::vector<float> verts;
2529
std::vector<int> faces;
2630
std::vector<int> edges;
31+
std::vector<float> normals;
2732
};
2833

2934
class IfcObject {
@@ -43,7 +48,8 @@ namespace IfcGeomObjects {
4348

4449
bool Next();
4550
const IfcGeomObject* Get();
46-
bool Init(const char* fn, bool world_coords = false);
51+
bool Init(const char* fn);
52+
void Settings(int setting, bool value);
4753
int Progress();
4854
const IfcObject* GetObject(int id);
4955
bool CleanUp();

0 commit comments

Comments
 (0)