bool STLedgerEntry::hasOneOwner () const { return (type_ != ltACCOUNT_ROOT) && (getFieldIndex (sfAccount) != -1); }
int pcl::io::saveOBJFile (const std::string &file_name, const pcl::PolygonMesh &mesh, unsigned precision) { if (mesh.cloud.data.empty ()) { PCL_ERROR ("[pcl::io::saveOBJFile] Input point cloud has no data!\n"); return (-1); } // Open file std::ofstream fs; fs.precision (precision); fs.open (file_name.c_str ()); /* Write 3D information */ // number of points int nr_points = mesh.cloud.width * mesh.cloud.height; // point size unsigned point_size = static_cast<unsigned> (mesh.cloud.data.size () / nr_points); // number of faces for header unsigned nr_faces = static_cast<unsigned> (mesh.polygons.size ()); // Do we have vertices normals? int normal_index = getFieldIndex (mesh.cloud, "normal_x"); // Write the header information fs << "####" << std::endl; fs << "# OBJ dataFile simple version. File name: " << file_name << std::endl; fs << "# Vertices: " << nr_points << std::endl; if (normal_index != -1) fs << "# Vertices normals : " << nr_points << std::endl; fs << "# Faces: " <<nr_faces << std::endl; fs << "####" << std::endl; // Write vertex coordinates fs << "# List of Vertices, with (x,y,z) coordinates, w is optional." << std::endl; for (int i = 0; i < nr_points; ++i) { int xyz = 0; for (size_t d = 0; d < mesh.cloud.fields.size (); ++d) { int c = 0; // adding vertex if ((mesh.cloud.fields[d].datatype == pcl::PCLPointField::FLOAT32) && ( mesh.cloud.fields[d].name == "x" || mesh.cloud.fields[d].name == "y" || mesh.cloud.fields[d].name == "z")) { if (mesh.cloud.fields[d].name == "x") // write vertices beginning with v fs << "v "; float value; memcpy (&value, &mesh.cloud.data[i * point_size + mesh.cloud.fields[d].offset + c * sizeof (float)], sizeof (float)); fs << value; if (++xyz == 3) break; fs << " "; } } if (xyz != 3) { PCL_ERROR ("[pcl::io::saveOBJFile] Input point cloud has no XYZ data!\n"); return (-2); } fs << std::endl; } fs << "# "<< nr_points <<" vertices" << std::endl; if(normal_index != -1) { fs << "# Normals in (x,y,z) form; normals might not be unit." << std::endl; // Write vertex normals for (int i = 0; i < nr_points; ++i) { int nxyz = 0; for (size_t d = 0; d < mesh.cloud.fields.size (); ++d) { int c = 0; // adding vertex if ((mesh.cloud.fields[d].datatype == pcl::PCLPointField::FLOAT32) && ( mesh.cloud.fields[d].name == "normal_x" || mesh.cloud.fields[d].name == "normal_y" || mesh.cloud.fields[d].name == "normal_z")) { if (mesh.cloud.fields[d].name == "normal_x") // write vertices beginning with vn fs << "vn "; float value; memcpy (&value, &mesh.cloud.data[i * point_size + mesh.cloud.fields[d].offset + c * sizeof (float)], sizeof (float)); fs << value; if (++nxyz == 3) break; fs << " "; } } if (nxyz != 3) { PCL_ERROR ("[pcl::io::saveOBJFile] Input point cloud has no normals!\n"); return (-2); } fs << std::endl; } fs << "# "<< nr_points <<" vertices normals" << std::endl; } fs << "# Face Definitions" << std::endl; // Write down faces if(normal_index == -1) { for(unsigned i = 0; i < nr_faces; i++) { fs << "f "; size_t j = 0; for (; j < mesh.polygons[i].vertices.size () - 1; ++j) fs << mesh.polygons[i].vertices[j] + 1 << " "; fs << mesh.polygons[i].vertices[j] + 1 << std::endl; } } else { for(unsigned i = 0; i < nr_faces; i++) { fs << "f "; size_t j = 0; for (; j < mesh.polygons[i].vertices.size () - 1; ++j) fs << mesh.polygons[i].vertices[j] + 1 << "//" << mesh.polygons[i].vertices[j] + 1 << " "; fs << mesh.polygons[i].vertices[j] + 1 << "//" << mesh.polygons[i].vertices[j] + 1 << std::endl; } } fs << "# End of File" << std::endl; // Close obj file fs.close (); return 0; }
bool SerializedLedgerEntry::hasOneOwner () { return (mType != ltACCOUNT_ROOT) && (getFieldIndex (sfAccount) != -1); }
bool STLedgerEntry::isThreadedType () const { return getFieldIndex (sfPreviousTxnID) != -1; }
bool SerializedLedgerEntry::isThreadedType () { return getFieldIndex (sfPreviousTxnID) != -1; }
void printResult(QSqlQuery query) { int pos; QList<TfieldDef> fields; int ncols; ncols = 0; for (pos = 0; pos <= query.record().count()-1;pos++) { ncols++; TfieldDef field; field.fieldName = query.record().field(pos).name(); switch (query.record().field(pos).type()) { case QVariant::Bool: field.fieldType = "BOL"; break; case QVariant::Char: field.fieldType = "CHR"; break; case QVariant::Date: field.fieldType = "DAT"; break; case QVariant::DateTime: field.fieldType = "DTM"; break; case QVariant::Double: field.fieldType = "DBL"; break; case QVariant::Int: field.fieldType = "INT"; break; case QVariant::String: field.fieldType = "STR"; break; case QVariant::Time: field.fieldType = "TIM"; break; case QVariant::UInt: field.fieldType = "UIN"; break; default: field.fieldType = "NA"; } fields.append(field); } int nrows; nrows = 0; while (query.next()) { nrows++; } nrows++; //Heads QVector<QVector<QString> > grid; grid.resize(nrows); int r; for(r=0; r<nrows; r++) { grid[r].resize(ncols); } //Append the field names for (pos = 0; pos <= fields.count()-1;pos++) grid[0][pos] = fields[pos].fieldName; for (pos = 0; pos <= fields.count()-1;pos++) grid[0][pos] = fields[pos].fieldName; r = 1; query.first(); QString value; while (query.isValid()) { for (pos = 0; pos <= fields.count()-1;pos++) { if (fields[pos].fieldType == "DBL") value = QString::number(query.value(getFieldIndex(query,fields[pos].fieldName)).toDouble(),'f',3); else { if (fields[pos].fieldName != "ogc_geom") value = query.value(getFieldIndex(query,fields[pos].fieldName)).toString().simplified(); else value = "Geometry data"; } grid[r][pos] = value; } r++; query.next(); } QVector< int> colSizes; colSizes.resize(ncols); for (pos = 0; pos <= ncols-1;pos++) colSizes[pos] = 0; //Get the maximum size of each column for (pos = 0; pos <= ncols-1;pos++) { for(r=0; r<nrows; r++) { if (grid[r][pos].length() +2 > colSizes[pos]) { colSizes[pos] = grid[r][pos].length() +2; } } } //Print the table printf("\n"); //Print top line for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print the columns headings for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixString(" " + grid[0][pos] + " ",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print separation for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print the values for (r=1;r<=nrows-1;r++) { printf("|"); for (pos=0;pos<= ncols-1;pos++) { printf(fixString(" " + grid[r][pos] + " ",colSizes[pos]).toLocal8Bit().data()); printf("|"); } printf("\n"); } //Print the end //Print separation for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); }
int writeTable (int fd, struct table *tableList, int index){ int len = strlen(tableList[index].table_name); if(write(fd, &len, sizeof(int)) != sizeof(int)){ perror("Writing error"); return -1; } printf("\nDEBUG: write table = '%s'\n", tableList[index].table_name); if(write(fd, tableList[index].table_name, len) != len){ perror("Writing error"); return -1; } if(write(fd, &tableList[index].column_count, sizeof(unsigned char)) != sizeof(unsigned char)){ perror("Writing error"); return -1; } int i; for(i = 0; i < tableList[index].column_count; i++){ printf("DEBUG: write column = '%s'\n", tableList[index].columns[i].column_name); newIndex++; if(write(fd, &newIndex, sizeof(int)) != sizeof(int)){ perror("Writing error"); return -1; } printf("DEBUG: write index = %d\n", newIndex); len = strlen(tableList[index].columns[i].column_name); if(write(fd, &len, sizeof(int)) != sizeof(int)){ perror("Writing error"); return -1; } printf("DEBUG: write len\n"); if(write(fd, tableList[index].columns[i].column_name, len) != len){ perror("Writing error"); return -1; } printf("DEBUG: write column name\n"); if(write(fd, &tableList[index].columns[i].type, sizeof(unsigned char)) != sizeof(unsigned char)){ perror("Writing error"); return -1; } printf("DEBUG: write type\n"); if(write(fd, &tableList[index].columns[i].constraints, sizeof(unsigned char)) != sizeof(unsigned char)){ perror("Writing error"); return -1; } printf("DEBUG: write constraints\n"); if (tableList[index].columns[i].constraints >= 8){ printf("DEBUG: getFieldIndex foreign table = '%s', foreign column = '%s'\n", tableList[index].columns[i].foreign_table->table_name, tableList[index].columns[i].foreign_key->column_name); int findex = getFieldIndex(tableList[index].columns[i].foreign_table->table_name, tableList[index].columns[i].foreign_key->column_name, tableList, index, i); if(findex < 0){ printf("Writing error: foreign key index was not found\n"); return -1; } if(write(fd, &findex, sizeof(int)) != sizeof(int)){ perror("Writing error"); return -1; } printf("DEBUG: write foreign findex = %d\n", findex); } } if(write(fd, "\n", 1) != 1){ perror("Writing error"); return -1; } return 0; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void PdmUiTableViewModel::setPdmData(PdmChildArrayFieldHandle* listField, const QString& configName) { beginResetModel(); m_pdmList = listField; m_currentConfigName = configName; PdmUiOrdering config; if (m_pdmList && m_pdmList->size() > 0) { PdmObjectHandle* firstObject = m_pdmList->at(0); PdmUiObjectHandle* uiObject = uiObj(firstObject); if (uiObject) { uiObject->uiOrdering(configName, config); } } const std::vector<PdmUiItem*>& uiItems = config.uiItems(); // Set all fieldViews to be unvisited std::map<QString, PdmUiFieldEditorHandle*>::iterator it; for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it) { it->second->setField(NULL); } m_modelColumnIndexToFieldIndex.clear(); for (size_t i = 0; i < uiItems.size(); ++i) { if (uiItems[i]->isUiHidden(configName)) continue; if (uiItems[i]->isUiGroup()) continue; { PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*>(uiItems[i]); PdmUiFieldEditorHandle* fieldEditor = NULL; // Find or create FieldEditor std::map<QString, PdmUiFieldEditorHandle*>::iterator it; it = m_fieldEditors.find(field->fieldHandle()->keyword()); if (it == m_fieldEditors.end()) { // If editor type is specified, find in factory if ( !uiItems[i]->uiEditorTypeName(configName).isEmpty() ) { fieldEditor = Factory<PdmUiFieldEditorHandle, QString>::instance()->create(field->uiEditorTypeName(configName)); } else { // Find the default field editor QString editorTypeName = qStringTypeName(*(field->fieldHandle())); // Handle a single value field with valueOptions: Make a combobox if (field->uiValue().type() != QVariant::List) { bool useOptionsOnly = true; QList<PdmOptionItemInfo> options = field->valueOptions( &useOptionsOnly); if (!options.empty()) { editorTypeName = PdmUiComboBoxEditor::uiEditorTypeName(); } } fieldEditor = Factory<PdmUiFieldEditorHandle, QString>::instance()->create(editorTypeName); } if (fieldEditor) { m_fieldEditors[field->fieldHandle()->keyword()] = fieldEditor; } } else { fieldEditor = it->second; } if (fieldEditor) { fieldEditor->setField(field); //TODO: Create/update is not required at this point, as UI is recreated in getEditorWidgetAndTransferOwnership() // Can be moved, but a move will require changes in PdmUiFieldEditorHandle fieldEditor->createWidgets(NULL); fieldEditor->updateUi(configName); int fieldIndex = getFieldIndex(field->fieldHandle()); m_modelColumnIndexToFieldIndex.push_back(fieldIndex); } } } // Remove all fieldViews not mentioned by the configuration from the layout std::vector< QString > fvhToRemoveFromMap; for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it) { if (it->second->field() == 0) { PdmUiFieldEditorHandle* fvh = it->second; delete fvh; fvhToRemoveFromMap.push_back(it->first); } } for (size_t i = 0; i < fvhToRemoveFromMap.size(); ++i) { m_fieldEditors.erase(fvhToRemoveFromMap[i]); } recreateTableItemEditors(); endResetModel(); }
int pcl::io::saveVTKFile (const std::string &file_name, const pcl::PolygonMesh &triangles, unsigned precision) { if (triangles.cloud.data.empty ()) { PCL_ERROR ("[pcl::io::saveVTKFile] Input point cloud has no data!\n"); return (-1); } // Open file std::ofstream fs; fs.precision (precision); fs.open (file_name.c_str ()); unsigned int nr_points = triangles.cloud.width * triangles.cloud.height; unsigned int point_size = static_cast<unsigned int> (triangles.cloud.data.size () / nr_points); // Write the header information fs << "# vtk DataFile Version 3.0\nvtk output\nASCII\nDATASET POLYDATA\nPOINTS " << nr_points << " float" << std::endl; // Iterate through the points for (unsigned int i = 0; i < nr_points; ++i) { int xyz = 0; for (size_t d = 0; d < triangles.cloud.fields.size (); ++d) { int count = triangles.cloud.fields[d].count; if (count == 0) count = 1; // we simply cannot tolerate 0 counts (coming from older converter code) int c = 0; if ((triangles.cloud.fields[d].datatype == sensor_msgs::PointField::FLOAT32) && ( triangles.cloud.fields[d].name == "x" || triangles.cloud.fields[d].name == "y" || triangles.cloud.fields[d].name == "z")) { float value; memcpy (&value, &triangles.cloud.data[i * point_size + triangles.cloud.fields[d].offset + c * sizeof (float)], sizeof (float)); fs << value; if (++xyz == 3) break; } fs << " "; } if (xyz != 3) { PCL_ERROR ("[pcl::io::saveVTKFile] Input point cloud has no XYZ data!\n"); return (-2); } fs << std::endl; } // Write vertices fs << "\nVERTICES " << nr_points << " " << 2*nr_points << std::endl; for (unsigned int i = 0; i < nr_points; ++i) fs << "1 " << i << std::endl; // Write polygons // compute the correct number of values: size_t triangle_size = triangles.polygons.size (); size_t correct_number = triangle_size; for (size_t i = 0; i < triangle_size; ++i) correct_number += triangles.polygons[i].vertices.size (); fs << "\nPOLYGONS " << triangle_size << " " << correct_number << std::endl; for (size_t i = 0; i < triangle_size; ++i) { fs << triangles.polygons[i].vertices.size () << " "; size_t j = 0; for (j = 0; j < triangles.polygons[i].vertices.size () - 1; ++j) fs << triangles.polygons[i].vertices[j] << " "; fs << triangles.polygons[i].vertices[j] << std::endl; } // Write RGB values int field_index = getFieldIndex (triangles.cloud, "rgb"); if (field_index != -1) { fs << "\nPOINT_DATA " << nr_points << "\nCOLOR_SCALARS scalars 3\n"; for (unsigned int i = 0; i < nr_points; ++i) { int count = triangles.cloud.fields[field_index].count; if (count == 0) count = 1; // we simply cannot tolerate 0 counts (coming from older converter code) int c = 0; if (triangles.cloud.fields[field_index].datatype == sensor_msgs::PointField::FLOAT32) { pcl::RGB color; memcpy (&color, &triangles.cloud.data[i * point_size + triangles.cloud.fields[field_index].offset + c * sizeof (float)], sizeof (RGB)); int r = color.r; int g = color.g; int b = color.b; fs << static_cast<float> (r) / 255.0f << " " << static_cast<float> (g) / 255.0f << " " << static_cast<float> (b) / 255.0f; } fs << std::endl; } } // Close file fs.close (); return (0); }