// Curve on a parametric surface entity (Type 142) bool InputIges::read_142(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); int int_fld; char chr_fld; istrstream* data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); int prmc_entry; int srf_entry; int srfc_entry; *data_line >> int_fld >> chr_fld; //-Entry-number *data_line >> int_fld >> chr_fld; //-Type of the curve *data_line >> srf_entry >> chr_fld; //-Pointer to surface *data_line >> prmc_entry >> chr_fld; //-Pointer to crv in param space *data_line >> srfc_entry >> chr_fld; //-Pointer to crv on the surface *data_line >> int_fld >> chr_fld; //-Preferred format // Update reference to the component IgesDirectoryEntry* comp_de = getDirectoryEntry(srfc_entry); comp_de->referingId = de->id; return result; }
// Line entity (Type 110) bool InputIges::read_110(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; int i,j; int int_fld; char chr_fld; static Point3 points[2]; locateParamEntry(de); //-Read one data-line readDataLine(lineBuffer, dataBuffer); istrstream* data_line = new istrstream(dataBuffer); //-Read two points *data_line >> int_fld >> chr_fld; // Entity-id for(i = 0; i < 2; i++) { readPoint(data_line, points[i]); } int body_layer = 0; createBodyElement2D(de->body, body_layer, points[0], points[1]); return result; }
// Trimmed (parametric) surface entity (Type 144) bool InputIges::read_144(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); int i; int int_fld, int_fldb[1]; char chr_fld; istrstream* data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); int srf_entry; int obnd_entry; int nof_ibnds; *data_line >> int_fld >> chr_fld; //-Entry-number *data_line >> srf_entry >> chr_fld; //-Pointer to surface *data_line >> int_fld >> chr_fld; //-Type of bounded surface // 0=the outer bndr is the bndr of D // 1=otherwise *data_line >> nof_ibnds >> chr_fld; //-Nof inner bndrs defined by simple closed curves *data_line >> obnd_entry >> chr_fld; //-Pointer to outer bndr of the surface // defining the inner bndr of the srf. IgesDirectoryEntry* comp_de; //-Read outer boundary on the surface (if defined!) if (obnd_entry > 0) { comp_de = getDirectoryEntry(obnd_entry); comp_de->referingId = de->id; } //-Read inner boundary defining curves (if defined!) if (nof_ibnds > 0) { int* bnd_id_table = new int[nof_ibnds]; int ibnd_entry; //-Read component row-ids and corresponding data-rows for(i = 0; i < nof_ibnds; i++) { readIntFields(data_line, 1, int_fldb); bnd_id_table[i] = int_fldb[0]; comp_de = getDirectoryEntry(int_fldb[0]); comp_de->referingId = de->id; } delete [] bnd_id_table; } return result; }
// Method reads one data field from string stream argument "data-line" // into buffer "buffer". void InputIges::getDataField(istrstream*& data_line, char* buffer) { // If there is no more data in the data-buffer, read next data-line if (dataLineStrmIsEmpty(*data_line)) { delete data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); } data_line->getline(buffer, DATA_PART_LEN, DATA_SEP); }
// This entry defines a bounded surface entity (Type 143) // It points to the surface and to the entry which defines the // bounding curves (fex. to an entry 141) bool InputIges::read_143(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); int i; int int_fld; char chr_fld; istrstream* data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); int nof_srfs, nof_bnds, nof_values; *data_line >> int_fld >> chr_fld; // entry-number *data_line >> nof_srfs >> chr_fld; // Nof surface entities int* srf_id_table = new int[nof_srfs]; nof_values = readIntFields(data_line, nof_srfs, srf_id_table); *data_line >> nof_bnds >> chr_fld; // Nof boundary entities int* bnd_id_table = new int[nof_bnds]; nof_values = readIntFields(data_line, nof_bnds, bnd_id_table); IgesDirectoryEntry* comp_de; int nof_refs; int* refs_table; // In 2D boundaries if ( modelDimension == ECIF_2D ) { nof_refs = nof_bnds; refs_table = bnd_id_table; // In 3D surfaces } else { nof_refs = nof_srfs; refs_table = srf_id_table; } for(i = 0; i < nof_refs; i++) { comp_de = getDirectoryEntry(refs_table[i]); comp_de->referingId = de->id; } delete [] bnd_id_table; delete [] srf_id_table; return result; }
// Boundary entity (Type 141) // This entry point to a untrimmed surface and to all curve elements // which define this surface as boundaries. bool InputIges::read_141(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); int i, j; int int_fld, int_fldb[1]; char chr_fld; istrstream* data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); //-Skip 4 (nbr sep) pairs: // Entry id // Type of srf representation (0=in trimmimg space, 1=in model space) // Preferred representation (0=unspec., 1=model space, 2=param. spcace, 3=equal) // Pointer to the DE of the untrimmed surface for(i = 0; i < 4; i++) { *data_line >> int_fld >> chr_fld; } //-Read number of curves in the boundary int nof_crvs; *data_line >> nof_crvs >> chr_fld; int* crv_id_table = new int[nof_crvs]; IgesDirectoryEntry* comp_de; //-Read component ids and update references for(i = 0; i < nof_crvs; i++) { for(j = 0; j < 4; j++) { readIntFields(data_line, 1, int_fldb); if (j == 0) { crv_id_table[i] = int_fldb[0]; comp_de = getDirectoryEntry(int_fldb[0]); comp_de->referingId = de->id; } } } delete [] crv_id_table; return result; }
float MeSerial::getValue(String key){ if(dataLineAvailable()){ String s = readDataLine(); if(stringLength(s)>2){ char * tmp; char * str; str = strtok_r((char*)s.c_str(), "=", &tmp); if(str!=NULL && strcmp(str,key.c_str())==0){ float v = atof(tmp); return v; } } } return 0; }
// Composite curve entity (Type 102) bool InputIges::read_102(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); int i; int int_fld, int_fldb[1]; char chr_fld; istrstream* data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); //-Read number of curves in the composite int nof_crvs; *data_line >> int_fld >> chr_fld; // Entry-id *data_line >> nof_crvs >> chr_fld; int* crv_id_table = new int[nof_crvs]; IgesDirectoryEntry* comp_de; //-Read component dir-ids and update the reference for(i = 0; i < nof_crvs; i++) { readIntFields(data_line, 1, int_fldb); crv_id_table[i] = int_fldb[0]; comp_de = getDirectoryEntry(int_fldb[0]); comp_de->referingId = de->id; } delete [] crv_id_table; return result; }
// Rational B-spline surface entity (Type 128) bool InputIges::read_128(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); int i,j; int int_fld; char chr_fld; //-Read one data-line readDataLine(lineBuffer, dataBuffer); istrstream* data_line = new istrstream(dataBuffer); int nof_cp, polyn_flg; int nof_cp_u, nof_kp_u, degree_u; int open_flg_u, periodic_flg_u; int nof_cp_v, nof_kp_v, degree_v; int open_flg_v, periodic_flg_v; *data_line >> int_fld >> chr_fld; //-Entry-id //---u-parameter *data_line >> nof_cp_u >> chr_fld; //-Nof control-points - 1 nof_cp_u += 1; *data_line >> degree_u >> chr_fld; //-Degree of basis functions nof_kp_u = nof_cp_u - degree_u + 1; //-Number of knot-points nof_kp_u += 2 * degree_u; // multiplicity at ends added!! //---v-parameter *data_line >> nof_cp_v >> chr_fld; //-Nof control-points - 1 nof_cp_v += 1; *data_line >> degree_v >> chr_fld; //-Degree of basis functions nof_kp_v = nof_cp_v - degree_v + 1; //-Number of knot-points nof_kp_v += 2 * degree_v; // multiplicity at ends added!! //---other parameters *data_line >> open_flg_u >> chr_fld; //-0= open curve *data_line >> open_flg_v >> chr_fld; //-0= open curve *data_line >> polyn_flg >> chr_fld; //-0=rational, 1=polynomial *data_line >> periodic_flg_u >> chr_fld; //-0=non-periodic *data_line >> periodic_flg_v >> chr_fld; //-0=non-periodic //-Read data into a temporary data-vector //Data length: (control-points (x,y,z,w)+ knots // total number of control-point (cp_u * cp_v array) nof_cp = nof_cp_u * nof_cp_v; int data_len = nof_kp_u + nof_kp_v + 4 * nof_cp ; double* crv_data = new double[data_len]; int nof_values = readDoubleFields(data_line, data_len, crv_data); //-Copy data from crv_data into proper components double* knots_u = new double[nof_kp_u]; double* knots_v = new double[nof_kp_v]; Point4* cpoints = new Point4[nof_cp]; int pos = 0; //-Knot-u points are first for(i=0; i < nof_kp_u; i++) knots_u[i] = crv_data[pos++]; //-Knot-u points are next for(i=0; i < nof_kp_v; i++) knots_v[i] = crv_data[pos++]; //-Weights are next for(i=0; i < nof_cp; i++) { cpoints[i][3] = crv_data[pos++]; } //-Control points are next //NOTE: In Iges points are not in homogenous form // We must transform them into (xw,yw,zw,w) format for(i=0; i < nof_cp; i++) { for(j=0; j < 3; j++) cpoints[i][j] = cpoints[i][3] * crv_data[pos++]; } ecif_FaceGeometry_X sP; sP.isRational = (polyn_flg == 0); sP.degree_u = degree_u; sP.degree_v = degree_v; sP.nofKnots_u = nof_kp_u; sP.nofKnots_v = nof_kp_v; sP.knots_u = knots_v; sP.knots_v = knots_v; sP.nofCpoints_u = nof_cp_u; sP.nofCpoints_v = nof_cp_v; sP.nofCpoints = nof_cp; sP.cpoints = cpoints; delete [] crv_data; //-Create nurbs-curve element //--Corner points BodyElement* vertices[4]; int vertex_ids[4]; static GcPoint point; int corner_ids[4]; corner_ids[0] = 0; corner_ids[1] = nof_cp_u - 1; corner_ids[2] = (nof_cp_u - 1) * nof_cp_v; corner_ids[3] = nof_cp_u * nof_cp_v - 1; // Create model vertex elements from nurbs corner points for (i = 0; i < 4; i++) { int c_id = corner_ids[i]; double w = sP.cpoints[c_id][3]; point.setPos(X, sP.cpoints[c_id][0]/w); point.setPos(Y, sP.cpoints[c_id][1]/w); point.setPos(Z, sP.cpoints[c_id][2]/w); vertices[i] = new BodyElement1D(&point); vertex_ids[i] = vertices[i]->Id(); model->addBodyElement(vertices[i]); } // Create a new element into the 3D-body BodyElement* body_elm = new BodyElement3D(4, vertex_ids, &sP); de->body->addElement(0, body_elm); model->addBodyElement(body_elm); return result; }
// Rational B-spline curve entity (Type 126) bool InputIges::read_126(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; static ecif_EdgeGeometry_X edge; init_trx_data(edge); locateParamEntry(de); int i,j, int_fld; char chr_fld; //-Read one data-line readDataLine(lineBuffer, dataBuffer); istrstream* data_line = new istrstream(dataBuffer); int nof_cp, nof_kp, degree; int planar_flg, open_flg, polyn_flg, periodic_flg; *data_line >> int_fld >> chr_fld; //-Entry-id *data_line >> nof_cp >> chr_fld; //-Nof control-points - 1 nof_cp += 1; *data_line >> degree >> chr_fld; //-Degree of basis functions nof_kp = nof_cp - degree + 1; //-Number of knot-points nof_kp += 2 * degree; // multiplicity at ends added!! *data_line >> planar_flg >> chr_fld; //-0= non-planar *data_line >> open_flg >> chr_fld; //-0= open curve *data_line >> polyn_flg >> chr_fld; //-0=rational, 1=polynomial *data_line >> periodic_flg >> chr_fld; //-0=non-periodic //-Read data into a temporary data-vector //Data length: (control-points (x,y,z,w)+ knots int data_len = 4 * nof_cp + nof_kp; double* crv_data = new double[data_len]; int nof_values = readDoubleFields(data_line, data_len, crv_data); //-Copy data from crv_data into proper components double* knots = new double[nof_kp]; Point4* ct_points = new Point4[nof_cp]; int pos = 0; //-Knot points are first for(i=0; i < nof_kp; i++) knots[i] = crv_data[pos++]; //-Then come weights for(i=0; i < nof_cp; i++) { ct_points[i][3] = crv_data[pos++]; } //-Then come control points edge.start = new Point3[1]; edge.end = new Point3[1]; for(i=0; i < nof_cp; i++) { for(j=0; j < 3; j++) { //-First control point is the start-point! if ( i == 0 ) { edge.start[0][j] = crv_data[pos]; } //-Last control point is the end-point! if ( i == nof_cp - 1 ) { edge.end[0][j] = crv_data[pos]; } //NOTE: In Iges points are not in homogenous form // We must transform them into (xw,yw,zw,w) format ct_points[i][j] = ct_points[i][3] * crv_data[pos++]; } } edge.isRational = (polyn_flg == 0); edge.degree = degree; edge.nofKnots = nof_kp; edge.knots = knots; edge.nofCpoints = nof_cp; edge.cpoints = ct_points; int body_layer = 0; createBodyElement2D(de->body, body_layer, edge); delete[] crv_data; reset_trx_data(edge); return result; }
// Copious data entity (Type 106) // Path of data points bool InputIges::read_106(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; locateParamEntry(de); bool is_closed = ( de->formNbr == 63 ); if ( modelDimension == ECIF_2D && is_closed ) { de->canBeBody = true; } if ( check_only_status ) { return result; } // Read geometry data // ================== int i,j; int int_fld; char chr_fld; double dbl_fld[1]; istrstream* data_line; readDataLine(lineBuffer, dataBuffer); data_line = new istrstream(dataBuffer); //-Read format of points int read_size; int point_size; int point_type; int nof_points; double common_z; *data_line >> int_fld >> chr_fld; // Entry-id *data_line >> point_type >> chr_fld; // Point type *data_line >> nof_points >> chr_fld; // Nof tuples readDoubleFields(data_line, 1, dbl_fld); // Common z coordinate (for type 1 points) if ( point_type == 1 ) { point_size = 2; read_size = 2; } else if ( point_type == 2 ) { point_size = 3; read_size = 3; } else if ( point_type == 3 ) { point_size = 6; read_size = 3; } Point3* points = new Point3[nof_points]; //-Read points int read_count = 0; for(i = 0; i < nof_points; i++) { points[i][0] = points[i][1] = points[i][2] = 0.0; for (j = 0; j < read_size; j++) { readDoubleFields(data_line, 1, dbl_fld); read_count++; // If we are reading relevant point data if ( read_count <= read_size ) { points[i][read_count - 1] = dbl_fld[0]; } // Reset counter if all point data read read_count = read_count % point_size; } } IgesDirectoryEntry* comp_de; //-We are reading a surface into a 3D model if ( modelDimension == ECIF_3D ) { // body->addElement(from this face-element etc....); result = false; } //-We are reading a body into a 2D model! else if ( modelDimension == ECIF_2D ) { int body_layer = 0; createBodyElement2D(de->body, body_layer, nof_points, points); } delete[] points; return result; }
// Circular arc entity (Type 100) bool InputIges::read_100(IgesDirectoryEntry* de, bool check_only_status) { bool result = true; static ecif_EdgeGeometry_X edge; init_trx_data(edge); edge.type = ECIF_CIRCLE; int i,j; int int_fld; double dbl_fldb[1]; char chr_fld; bool is_closed; static Point3 points[3]; locateParamEntry(de); //-Read one data-line readDataLine(lineBuffer, dataBuffer); istrstream* data_line = new istrstream(dataBuffer); //-Read center and two points *data_line >> int_fld >> chr_fld; // Entity-id readDoubleFields(data_line, 1, dbl_fldb); // z-inclination for(i = 0; i < 3; i++) { points[i][2] = 0.0; for (j = 0; j < 2; j++) { readDoubleFields(data_line, 1, dbl_fldb); points[i][j] = dbl_fldb[0]; } } if ( isZero(dist3(points[1], points[2])) ) { is_closed = true; } else { is_closed = false; } if ( modelDimension == ECIF_2D && is_closed ) { de->canBeBody = true; } if ( check_only_status ) { return result; } // Create body element // =================== edge.location = new Point3[1]; edge.start = new Point3[1]; edge.end = new Point3[1]; for (i = 0; i < 3; i++) { edge.location[0][i] = points[0][i]; edge.start[0][i] = points[1][i]; edge.end[0][i] = points[2][i]; } int body_layer = 0; createBodyElement2D(de->body, body_layer, edge); reset_trx_data(edge); return result; }
Matrix *UserSpace::loadFrom(const char *filename, ...) { ifstream sfile(filename, ios::in); string line; Matrix *curM; int state = 0; string varName; int rows(0), cols(0); vector<OM_SUPPORT_TYPE> elements; int curRows(0), curCols(0); int error = 0; while(getline(sfile, line)) { if (line.size() == 0) continue; if (state == 0) // expecting a new matrix { if (isComment(line)) { curRows = 0; curCols = 0; if(containName(line)) { varName = getName(line); state = 0; } else if (isRow(line)) { rows = getRows(line); state = 0; } else if (isCol(line)) { cols = getCols(line); state = 0; } } else { curCols = readDataLine(elements, line); curRows++; if (cols != 0 && cols != curCols) { error = 1; break; } state = 1; } } else if (state = 1) // in the middle of reading data { if (isComment(line)) // a new matrix starts { if (curRows > 0) { if (rows != 0 && rows != curRows) { error = 1; break; } // store the data int dims[2]; dims[0] = curRows; dims[1] = curCols; const OM_SUPPORT_TYPE *e = &elements[0]; Matrix *m = new Matrix(NULL, 2, dims, e); if (varName.size() != 0) updateVar(varName.c_str(), m); else assert(0); // todo } curRows = 0; curCols = 0; varName = ""; state = 0; elements.clear(); // processing the current line if(containName(line)) { varName = getName(line); state = 0; } else if (isRow(line)) { rows = getRows(line); state = 0; } else if (isCol(line)) { cols = getCols(line); state = 0; } } else { // read data curCols = readDataLine(elements, line); curRows++; if (cols != 0 && cols != curCols) throw ExeException("Error loading the file\n"); state = 1; } } } if (state = 1) { if (curRows > 0) { if (rows != 0 && rows != curRows) { error = 1; } else { // store the data int dims[2]; dims[0] = curRows; dims[1] = curCols; Matrix *m = new Matrix(NULL, 2, dims, &elements[0]); if (varName.size() != 0) updateVar(varName.c_str(), m); else assert(0); // todo } } } sfile.close(); if (error == 1) throw ExeException("Error loading the file."); }