mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Account for unit magnitude in matrix translation part when CONVERT_BACK_UNITS is enabled
This commit is contained in:
@@ -240,9 +240,19 @@ IfcGeomObjects::IfcObject::IfcObject(
|
||||
, _guid(guid)
|
||||
{
|
||||
// Convert the gp_Trsf into a 4x3 Matrix
|
||||
for( int i = 1; i < 5; ++ i )
|
||||
for ( int j = 1; j < 4; ++ j )
|
||||
_matrix.push_back((float)trsf.Value(j,i));
|
||||
// Note that in case the CONVERT_BACK_UNITS setting is enabled
|
||||
// the translation component of the matrix needs to be divided
|
||||
// by the magnitude of the IFC model length unit because
|
||||
// internally in IfcOpenShell everything is measured in meters.
|
||||
for(int i = 1; i < 5; ++i) {
|
||||
for (int j = 1; j < 4; ++j) {
|
||||
const double trsf_value = trsf.Value(j,i);
|
||||
const double matrix_value = i == 4 && convert_back_units
|
||||
? trsf_value / IfcGeom::GetValue(IfcGeom::GV_LENGTH_UNIT)
|
||||
: trsf_value;
|
||||
_matrix.push_back(static_cast<float>(matrix_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IfcGeomObjects::IfcGeomShapeModelObject::IfcGeomShapeModelObject(
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file is part of IfcOpenShell. *
|
||||
* *
|
||||
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the Lesser GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3.0 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* IfcOpenShell is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* Lesser GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the Lesser GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This examples exposes the IfcOpenShell API through a command-based stdin *
|
||||
* interface *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../ifcgeom/IfcGeomObjects.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#define PRODUCT ("IfcOpenShell-0.2.3")
|
||||
#define ACK ("y")
|
||||
#define NEG ("n")
|
||||
#define CONFIRM ("ok")
|
||||
#define CLOSED ("No opened file")
|
||||
#define QUIT ("Bye :)")
|
||||
#define UNKNOWN ("Unknown command")
|
||||
|
||||
void send_msg(const char* c) {
|
||||
std::cout.write(c,strlen(c));
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
void send_msg(const std::string& s) {
|
||||
std::cout << s << std::flush;
|
||||
}
|
||||
|
||||
int main ( int argc, char** argv ) {
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
_setmode(_fileno(stdout), _O_BINARY);
|
||||
std::cout.setf(std::ios_base::binary);
|
||||
#endif
|
||||
bool has_more = false;
|
||||
send_msg(PRODUCT);
|
||||
const IfcGeomObjects::IfcGeomObject* ifc_geom = 0;
|
||||
while (1) {
|
||||
std::string command;
|
||||
std::cin >> command;
|
||||
if ( command == "load" ) {
|
||||
std::string fn;
|
||||
std::getline(std::cin,fn);
|
||||
fn = fn.erase(0,fn.find_first_not_of(" "));
|
||||
has_more = IfcGeomObjects::Init(fn.c_str(),true,0,&std::cerr);
|
||||
send_msg(has_more ? ACK : NEG);
|
||||
} else if ( command == "loadstdin" ) {
|
||||
send_msg(CONFIRM);
|
||||
int len;
|
||||
std::cin >> len;
|
||||
send_msg(CONFIRM);
|
||||
has_more = IfcGeomObjects::Init(std::cin,len,true,0,&std::cerr);
|
||||
send_msg(has_more ? ACK : NEG);
|
||||
} else if ( command == "get" ) {
|
||||
if ( ! has_more ) send_msg(CLOSED);
|
||||
else {
|
||||
ifc_geom = IfcGeomObjects::Get();
|
||||
const int vcount = ifc_geom->mesh->verts.size() / 3;
|
||||
std::cout.write((char*)&vcount,sizeof(int));
|
||||
std::cout.write((char*)&ifc_geom->mesh->verts[0],sizeof(float)*vcount*3);
|
||||
const int fcount = ifc_geom->mesh->faces.size() / 3;
|
||||
std::cout.write((char*)&fcount,sizeof(int));
|
||||
std::cout.write((char*)&ifc_geom->mesh->faces[0],sizeof(int)*fcount*3);
|
||||
std::cout.flush();
|
||||
}
|
||||
} else if ( command == "type" ) {
|
||||
if ( ifc_geom ) send_msg(ifc_geom->type);
|
||||
else send_msg(CLOSED);
|
||||
} else if ( command == "guid" ) {
|
||||
if ( ifc_geom ) send_msg(ifc_geom->guid);
|
||||
else send_msg(CLOSED);
|
||||
} else if ( command == "next" ) {
|
||||
if ( !has_more ) send_msg(CLOSED);
|
||||
else {
|
||||
has_more = IfcGeomObjects::Next();
|
||||
if ( ! has_more )
|
||||
IfcGeomObjects::CleanUp();
|
||||
send_msg(has_more ? ACK : NEG);
|
||||
}
|
||||
} else if ( command == "quit" || command == "exit" ) {
|
||||
send_msg(QUIT);
|
||||
break;
|
||||
} else {
|
||||
send_msg(UNKNOWN);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user