1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "UNV2420_Structure.hxx"
24 #include "UNV_Utilities.hxx"
32 using namespace UNV2420;
34 static string _label_dataset = "2420";
36 void UNV2420::Read(std::ifstream& in_stream,
37 std::string& part_name, // can re-store a mesh name
41 EXCEPTION(runtime_error,"ERROR: Input file not good.");
44 * adjust the \p istream to our
47 if(!beginning_of_dataset(in_stream,_label_dataset))
53 in_stream >> part_uid; // Record 1
54 part_name = read_line( in_stream ); // Record 2
56 while ( !in_stream.eof() )
61 in_stream >> aRec.coord_sys_label;
62 if ( aRec.coord_sys_label == -1 ) // end of dataset is reached
64 in_stream >> aRec.coord_sys_type;
65 in_stream >> aRec.coord_sys_color;
67 aRec.coord_sys_name = read_line( in_stream ); // Record 4
69 // Records 5-8: rows of Transformation Matrix
70 for ( int row = 0; row < 4; ++row )
71 for ( int i = 0; i < 3; i++ )
74 aRec.matrix[row][i] = D_to_e(num_buf);
76 // Store a CS data only if it requires conversion into the global Cartesian CS
77 if ( aRec.coord_sys_type != 0 || !aRec.isIdentityMatrix() ) // 0 - Cartesian CS
78 theDataSet.push_back( aRec );
83 void UNV2420::Write(std::ofstream& out_stream,
84 const std::string& part_name)
85 // const TDataSet& theDataSet)
87 if(!out_stream.good())
88 EXCEPTION(runtime_error,"ERROR: Output file not good.");
90 out_stream<<" -1" << endl;
91 out_stream<<" "<<_label_dataset << endl;
93 out_stream<<" 1" << endl; // R1: Part UID
94 if ( part_name.empty() )
95 out_stream<<"SMESH_Mesh" << endl; // R2: Part Name
97 out_stream<< part_name << endl;
98 out_stream<<" 1 0 0" << endl; // R3: Label, Type, Color
100 out_stream<<"Global Cartesian Coordinate System" << endl; // R4: Name
101 out_stream<<" 1.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0" << endl;
102 out_stream<<" 0.0000000000000000E+0 1.0000000000000000E+0 0.0000000000000000E+0" << endl;
103 out_stream<<" 0.0000000000000000E+0 0.0000000000000000E+0 1.0000000000000000E+0" << endl;
104 out_stream<<" 0.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0" << endl;
106 out_stream<<" -1" << endl;
110 bool UNV2420::TRecord::isIdentityMatrix() const
112 bool isIdentity = true;
113 for ( int row = 0; row < 4 && isIdentity; ++row )
114 for ( int i = 0; i < 3; i++ )
116 if ( matrix[row][i] != ( row==i ? 1. : 0. ))
125 void UNV2420::TRecord::ApplyMatrix( double* c ) const
127 const double x = matrix[0][0] * c[0] + matrix[0][1] * c[1] + matrix[0][2] * c[2];
128 const double y = matrix[1][0] * c[0] + matrix[1][1] * c[1] + matrix[1][2] * c[2];
129 const double z = matrix[2][0] * c[0] + matrix[2][1] * c[1] + matrix[2][2] * c[2];
130 c[0] = x + matrix[3][0];
131 c[1] = y + matrix[3][1];
132 c[2] = z + matrix[3][2];
135 void UNV2420::TRecord::FromCylindricalCS( double* coords )
137 const double x = coords[0] * cos( coords[1] );
138 const double y = coords[0] * sin( coords[1] );
143 void UNV2420::TRecord::FromSphericalCS ( double* coords )
145 const double sin2 = sin( coords[2] );
146 const double x = coords[0] * cos( coords[1] ) * sin2;
147 const double y = coords[0] * sin( coords[1] ) * sin2;
148 const double z = coords[0] * cos( coords[2] );