/*! * Export surface tasselation to DGF file * * \param[in] dgf_name name of dgf file * * \result on output returns an error flag for I/O error */ unsigned short SurfUnstructured::exportDGF(const string &dgf_name) { // ====================================================================== // // VARIABLES DECLARATION // // ====================================================================== // // Local variables DGFObj dgf_in(dgf_name); int nV = getVertexCount(), nS = getCellCount(); int v, nv; long vcount, ccount, idx; std::vector<std::array<double, 3>> vertex_list(nV); std::vector<std::vector<int>> simplex_list(nS); std::unordered_map<long, long> vertex_map; // Counters VertexIterator v_, ve_; CellIterator c_, ce_; // ====================================================================== // // EXPORT DATA // // ====================================================================== // // Create vertex list ve_ = vertexEnd(); vcount = 0; for (v_ = vertexBegin(); v_ != ve_; ++v_) { idx = v_->getId(); vertex_list[vcount] = v_->getCoords(); vertex_map[idx] = vcount; ++vcount; } //next v_ // Add cells ce_ = cellEnd(); ccount = 0; for (c_ = cellBegin(); c_ != ce_; ++c_) { nv = c_->getVertexCount(); simplex_list[ccount].resize(nv); for (v = 0; v < nv; ++v) { simplex_list[ccount][v] = vertex_map[c_->getVertex(v)]; } //next v ++ccount; } //next c_ // Read vertices and cells from DGF file dgf_in.save(nV, nS, vertex_list, simplex_list); return 0; }
void KPImageDialogPreview::showPreview(const QUrl& url) { if (!url.isValid()) { clearPreview(); return; } if (url != d->currentUrl) { QString make, model, dateTime, aperture, focalLength, exposureTime, sensitivity; QString unavailable(i18n("<i>unavailable</i>")); clearPreview(); d->currentUrl = url; if (d->iface) { d->iface->thumbnail(d->currentUrl, 256); } else { qCDebug(KIPIPLUGINS_LOG) << "No KIPI interface available : thumbnails will not generated."; } // Try to use Metadata Processor from KIPI host to identify image. if (d->meta && d->meta->load(d->currentUrl) && (d->meta->hasExif() || d->meta->hasXmp())) { make = d->meta->getExifTagString(QLatin1String("Exif.Image.Make")); if (make.isEmpty()) make = d->meta->getXmpTagString(QLatin1String("Xmp.tiff.Make")); model = d->meta->getExifTagString(QLatin1String("Exif.Image.Model")); if (model.isEmpty()) model = d->meta->getXmpTagString(QLatin1String("Xmp.tiff.Model")); if (d->meta->getImageDateTime().isValid()) dateTime = QLocale().toString(d->meta->getImageDateTime(), QLocale::ShortFormat); aperture = d->meta->getExifTagString(QLatin1String("Exif.Photo.FNumber")); if (aperture.isEmpty()) { aperture = d->meta->getExifTagString(QLatin1String("Exif.Photo.ApertureValue")); if (aperture.isEmpty()) { aperture = d->meta->getXmpTagString(QLatin1String("Xmp.exif.FNumber")); if (aperture.isEmpty()) aperture = d->meta->getXmpTagString(QLatin1String("Xmp.exif.ApertureValue")); } } focalLength = d->meta->getExifTagString(QLatin1String("Exif.Photo.FocalLength")); if (focalLength.isEmpty()) focalLength = d->meta->getXmpTagString(QLatin1String("Xmp.exif.FocalLength")); exposureTime = d->meta->getExifTagString(QLatin1String("Exif.Photo.ExposureTime")); if (exposureTime.isEmpty()) { exposureTime = d->meta->getExifTagString(QLatin1String("Exif.Photo.ShutterSpeedValue")); if (exposureTime.isEmpty()) { exposureTime = d->meta->getXmpTagString(QLatin1String("Xmp.exif.ExposureTime")); if (exposureTime.isEmpty()) exposureTime = d->meta->getXmpTagString(QLatin1String("Xmp.exif.ShutterSpeedValue")); } } sensitivity = d->meta->getExifTagString(QLatin1String("Exif.Photo.ISOSpeedRatings")); if (sensitivity.isEmpty()) { sensitivity = d->meta->getExifTagString(QLatin1String("Exif.Photo.ExposureIndex")); if (sensitivity.isEmpty()) { sensitivity = d->meta->getXmpTagString(QLatin1String("Xmp.exif.ISOSpeedRatings")); if (sensitivity.isEmpty()) sensitivity = d->meta->getXmpTagString(QLatin1String("Xmp.exif.ExposureIndex")); } } } if (make.isEmpty()) make = unavailable; if (model.isEmpty()) model = unavailable; if (dateTime.isEmpty()) dateTime = unavailable; if (aperture.isEmpty()) aperture = unavailable; if (focalLength.isEmpty()) focalLength = unavailable; if (exposureTime.isEmpty()) exposureTime = unavailable; if (sensitivity.isEmpty()) sensitivity = unavailable; else sensitivity = i18n("%1 ISO", sensitivity); QString identify(QString::fromLatin1("<qt><center>")); QString cellBeg(QString::fromLatin1("<tr><td><nobr><font size=-1>")); QString cellMid(QString::fromLatin1("</font></nobr></td><td><nobr><font size=-1>")); QString cellEnd(QString::fromLatin1("</font></nobr></td></tr>")); identify += QString::fromLatin1("<table cellspacing=0 cellpadding=0>"); identify += cellBeg + i18n("<i>Make:</i>") + cellMid + make + cellEnd; identify += cellBeg + i18n("<i>Model:</i>") + cellMid + model + cellEnd; identify += cellBeg + i18n("<i>Created:</i>") + cellMid + dateTime + cellEnd; identify += cellBeg + i18n("<i>Aperture:</i>") + cellMid + aperture + cellEnd; identify += cellBeg + i18n("<i>Focal:</i>") + cellMid + focalLength + cellEnd; identify += cellBeg + i18n("<i>Exposure:</i>") + cellMid + exposureTime + cellEnd; identify += cellBeg + i18n("<i>Sensitivity:</i>") + cellMid + sensitivity + cellEnd; identify += QString::fromLatin1("</table></center></qt>"); d->infoLabel->setText(identify); } }
void KPImageDialogPreview::showPreview(const KUrl& url) { if (!url.isValid()) { clearPreview(); return; } if (url != d->currentUrl) { QString make, model, dateTime, aperture, focalLength, exposureTime, sensitivity; QString unavailable(i18n("<i>unavailable</i>")); clearPreview(); d->currentUrl = url; if (d->iface) { d->iface->thumbnail(d->currentUrl, 256); } else { if ( !d->currentUrl.isValid() ) return; #if KDE_IS_VERSION(4,7,0) KFileItemList items; items.append(KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->currentUrl, true)); KIO::PreviewJob* job = KIO::filePreview(items, QSize(256, 256)); #else KIO::PreviewJob* job = KIO::filePreview(d->currentUrl, 256); #endif connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)), this, SLOT(slotKDEPreview(KFileItem,QPixmap))); connect(job, SIGNAL(failed(KFileItem)), this, SLOT(slotKDEPreviewFailed(KFileItem))); } // Try to use libkexiv2 to identify image. if (d->metaIface.load(d->currentUrl.path()) && (d->metaIface.hasExif() || d->metaIface.hasXmp())) { make = d->metaIface.getExifTagString("Exif.Image.Make"); if (make.isEmpty()) make = d->metaIface.getXmpTagString("Xmp.tiff.Make"); model = d->metaIface.getExifTagString("Exif.Image.Model"); if (model.isEmpty()) model = d->metaIface.getXmpTagString("Xmp.tiff.Model"); if (d->metaIface.getImageDateTime().isValid()) dateTime = KGlobal::locale()->formatDateTime(d->metaIface.getImageDateTime(), KLocale::ShortDate, true); aperture = d->metaIface.getExifTagString("Exif.Photo.FNumber"); if (aperture.isEmpty()) { aperture = d->metaIface.getExifTagString("Exif.Photo.ApertureValue"); if (aperture.isEmpty()) { aperture = d->metaIface.getXmpTagString("Xmp.exif.FNumber"); if (aperture.isEmpty()) aperture = d->metaIface.getXmpTagString("Xmp.exif.ApertureValue"); } } focalLength = d->metaIface.getExifTagString("Exif.Photo.FocalLength"); if (focalLength.isEmpty()) focalLength = d->metaIface.getXmpTagString("Xmp.exif.FocalLength"); exposureTime = d->metaIface.getExifTagString("Exif.Photo.ExposureTime"); if (exposureTime.isEmpty()) { exposureTime = d->metaIface.getExifTagString("Exif.Photo.ShutterSpeedValue"); if (exposureTime.isEmpty()) { exposureTime = d->metaIface.getXmpTagString("Xmp.exif.ExposureTime"); if (exposureTime.isEmpty()) exposureTime = d->metaIface.getXmpTagString("Xmp.exif.ShutterSpeedValue"); } } sensitivity = d->metaIface.getExifTagString("Exif.Photo.ISOSpeedRatings"); if (sensitivity.isEmpty()) { sensitivity = d->metaIface.getExifTagString("Exif.Photo.ExposureIndex"); if (sensitivity.isEmpty()) { sensitivity = d->metaIface.getXmpTagString("Xmp.exif.ISOSpeedRatings"); if (sensitivity.isEmpty()) sensitivity = d->metaIface.getXmpTagString("Xmp.exif.ExposureIndex"); } } } else { // Try to use libkdcraw interface to identify image. DcrawInfoContainer info; KDcraw dcrawIface; dcrawIface.rawFileIdentify(info, d->currentUrl.path()); if (info.isDecodable) { if (!info.make.isEmpty()) make = info.make; if (!info.model.isEmpty()) model = info.model; if (info.dateTime.isValid()) dateTime = KGlobal::locale()->formatDateTime(info.dateTime, KLocale::ShortDate, true); if (info.aperture != -1.0) aperture = QString::number(info.aperture); if (info.focalLength != -1.0) focalLength = QString::number(info.focalLength); if (info.exposureTime != -1.0) exposureTime = QString::number(info.exposureTime); if (info.sensitivity != -1) sensitivity = QString::number(info.sensitivity); } else { d->infoLabel->clear(); return; } } if (make.isEmpty()) make = unavailable; if (model.isEmpty()) model = unavailable; if (dateTime.isEmpty()) dateTime = unavailable; if (aperture.isEmpty()) aperture = unavailable; if (focalLength.isEmpty()) focalLength = unavailable; if (exposureTime.isEmpty()) exposureTime = unavailable; if (sensitivity.isEmpty()) sensitivity = unavailable; else sensitivity = i18n("%1 ISO", sensitivity); QString identify("<qt><center>"); QString cellBeg("<tr><td><nobr><font size=-1>"); QString cellMid("</font></nobr></td><td><nobr><font size=-1>"); QString cellEnd("</font></nobr></td></tr>"); identify += "<table cellspacing=0 cellpadding=0>"; identify += cellBeg + i18n("<i>Make:</i>") + cellMid + make + cellEnd; identify += cellBeg + i18n("<i>Model:</i>") + cellMid + model + cellEnd; identify += cellBeg + i18n("<i>Created:</i>") + cellMid + dateTime + cellEnd; identify += cellBeg + i18n("<i>Aperture:</i>") + cellMid + aperture + cellEnd; identify += cellBeg + i18n("<i>Focal:</i>") + cellMid + focalLength + cellEnd; identify += cellBeg + i18n("<i>Exposure:</i>") + cellMid + exposureTime + cellEnd; identify += cellBeg + i18n("<i>Sensitivity:</i>") + cellMid + sensitivity + cellEnd; identify += "</table></center></qt>"; d->infoLabel->setText(identify); } }
/*! * Export surface tasselation in a STL format. No check is perfomed on element type * therefore tasselation containing vertex, line or quad elements will produce * ill-formed stl triangulation. * * \param[in] stl_name name of the stl file * \param[in] isBinary flag for binary (true) or ASCII (false) file * \param[in] exportInternalsOnly flag for exporting only internal cells (true), * or internal+ghost cells (false). * * \result on output returns an error flag for I/O error. */ unsigned short SurfUnstructured::exportSTL(const string &stl_name, const bool &isBinary, bool exportInternalsOnly) { // ====================================================================== // // VARIABLES DECLARATION // // ====================================================================== // // Local variables int nVertex; int nSimplex; vector<array<double, 3>> vertexList; vector<array<double, 3>> normalList; vector<vector<int>> connectivityList; unordered_map<long, long> vertexMap; // Counters int v_count ,j; vector<array<double, 3>>::iterator i_; vector<vector<int>>::iterator j_; vector<int>::iterator k_, ke_; VertexIterator v_, ve_; CellIterator c_, cb_, ce_; // ====================================================================== // // INITIALIZE DATA STRUCTURE // // ====================================================================== // nSimplex = m_nInternals; if (!exportInternalsOnly) nSimplex += m_nGhosts; vertexList.resize(getVertexCount()); normalList.resize(nSimplex); connectivityList.resize(nSimplex, vector<int>(3, 0)); // ====================================================================== // // CREATE VERTEX LIST // // ====================================================================== // i_ = vertexList.begin(); ve_ = vertexEnd(); v_count = 0; for (v_ = vertexBegin(); v_ != ve_; ++v_) { // Store vertex coordinates *i_ = v_->getCoords(); vertexMap[v_->getId()] = v_count; // Update counters ++v_count; ++i_; } //next v_ nVertex = getVertexCount(); // ====================================================================== // // CREATE CONNECTIVITY // // ====================================================================== // if (exportInternalsOnly) { cb_ = internalBegin(); ce_ = internalEnd(); } else { cb_ = cellBegin(); ce_ = cellEnd(); } i_ = normalList.begin(); j_ = connectivityList.begin(); for (c_ = cb_; c_ != ce_; ++c_) { // Build normals *i_ = std::move(evalFacetNormal(c_->getId())); // Build connectivity ke_ = j_->end(); j = 0; for (k_ = j_->begin(); k_ != ke_; ++k_) { *k_ = vertexMap[c_->getVertex(j)]; ++j; } //next k_ // Update counters ++j_; ++i_; } //next c_ // ====================================================================== // // EXPORT STL DATA // // ====================================================================== // STLObj STL(stl_name, isBinary); STL.save("", nVertex, nSimplex, vertexList, normalList, connectivityList); return 0; }
/*! * Extract the edge network from surface mesh. If adjacencies are not built * edges shared by more than 1 element are counted twice. Edges are appended * to the content of the input SurfUnstructured * * \param[in,out] net on output stores the network of edges */ void SurfUnstructured::extractEdgeNetwork(SurfUnstructured &net) { // ====================================================================== // // VARIABLES DECLARATION // // ====================================================================== // // Local variables bool check; int n_faces, n_adj, n_vert; long id; vector<int> face_loc_connect; vector<long> face_connect; // Counters int i, j; vector<int>::const_iterator i_; vector<long>::iterator j_; VertexIterator v_, ve_ = vertexEnd(); CellIterator c_, ce_ = cellEnd(); // ====================================================================== // // INITIALIZE DATA STRUCTURE // // ====================================================================== // net.reserveCells(net.getCellCount() + countFaces()); net.reserveVertices(net.getVertexCount() + getVertexCount()); // ====================================================================== // // ADD VERTEX TO net // // ====================================================================== // for (v_ = vertexBegin(); v_ != ve_; ++v_) { net.addVertex(v_->getCoords(), v_->getId()); } //next v_ // ====================================================================== // // ADD EDGES // // ====================================================================== // for (c_ = cellBegin(); c_ != ce_; ++c_) { id = c_->getId(); n_faces = c_->getFaceCount(); for (i = 0; i < n_faces; ++i) { check = true; n_adj = c_->getAdjacencyCount(i); for (j = 0; j < n_adj; ++j) { check = check && (id > c_->getAdjacency(i, j)); } //next j if (check) { face_loc_connect = c_->getFaceLocalConnect(i); n_vert = face_loc_connect.size(); face_connect.resize(n_vert); j_ = face_connect.begin(); for (i_ = face_loc_connect.cbegin(); i_ != face_loc_connect.cend(); ++i_) { *j_ = c_->getVertex(*i_); ++j_; } //next i_ net.addCell(c_->getFaceType(i), true, face_connect); } } //next i } //next c_ return; }