Skip to content

Commit

Permalink
[fix] memory overload
Browse files Browse the repository at this point in the history
  • Loading branch information
scially committed Jan 11, 2024
1 parent 4970846 commit 6f14903
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 109 deletions.
2 changes: 2 additions & 0 deletions include/OSGConvert/B3DMTile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ namespace scially {
// class OSGTile
B3DMTile() = default;
virtual ~B3DMTile() = default;

private:
};
}
29 changes: 4 additions & 25 deletions include/OSGConvert/OSGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ namespace scially {
template <typename T>
using QPointerList = QList<QSharedPointer<T>>;

#if __cplusplus == 202002L
using remove_cvref_t = std::remove_cvref_t;
#else
template<class T>
struct remove_cvref
{
typedef std::remove_cv_t<std::remove_reference_t<T>> type;
};
template< class T >
using remove_cvref_t = typename remove_cvref<T>::type;
#endif

constexpr double SPLIT_PIXEL = 512;

// for TileNode and TileNodeView, use Pointer as child node type?
Expand All @@ -42,8 +30,8 @@ namespace scially {
}

template <typename T>
bool isSameKindAs(const OSGNode* obj) const {
return dynamic_cast<const remove_cvref_t<T>*>(obj) != nullptr;
bool isSameKindAs() const {
return dynamic_cast<const T*>(this) != nullptr;
}

QString fileName() const {
Expand Down Expand Up @@ -124,7 +112,8 @@ namespace scially {
QString mFileName;
};

class OSGIndexNode: public OSGNode, public QEnableSharedFromThis<OSGIndexNode> {
class OSGIndexNode: public OSGNode, public QEnableSharedFromThis<OSGIndexNode>
{
public:
// child nodes
virtual QString name() const override {
Expand Down Expand Up @@ -157,10 +146,6 @@ namespace scially {

virtual bool parentIndex(uint32_t z, int32_t& x, int32_t& y) const;

osg::ref_ptr<osg::Node> osgNode() const {
return mOSGNode;
}

osg::BoundingBoxd boundingBox() const {
return mBoundingBox;
}
Expand All @@ -177,10 +162,6 @@ namespace scially {
return mGeometricError;
}

osg::ref_ptr<osg::Node>& osgNode() {
return mOSGNode;
}

// convert
QSharedPointer<OSGIndexNode> toB3DM(
const SpatialTransform& transform,
Expand Down Expand Up @@ -249,8 +230,6 @@ namespace scially {
}

protected:
osg::ref_ptr<osg::Node> mOSGNode;

int32_t mXIndex = -1;
int32_t mYIndex = -1;
int32_t mZIndex = 1;
Expand Down
9 changes: 9 additions & 0 deletions include/OSGConvert/OSGVirtualTile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ namespace scially {
}

virtual ~OSGVirtualTile() = default;

const osg::Node* osgNode() const {
return mOSGNode;
}
osg::ref_ptr<osg::Node>& osgNode() {
return mOSGNode;
}
private:
osg::ref_ptr<osg::Node> mOSGNode;
};
}
2 changes: 1 addition & 1 deletion src/CesiumGLTF/CesiumMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace scially {
void addGltfMesh(const CesiumMesh& m) {
if (m.vertex.isEmpty() || m.indices.isEmpty())
{
qWarning() << "empty packed mesh";
qWarning( "empty packed mesh");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/CesiumGLTF/CesiumTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace scially {
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
qCritical() << "don't support osg dds texture format";
qCritical("don't support osg dds texture format");
return false;
default:
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/CesiumMath/SpatialReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace scially {
mOrigin = origin;
OGRSpatialReference srf;
if (!importFromStr(srf, inSrs)) {
qCritical() << "parse crs" << inSrs << "failed";
qCritical("parse crs %s failed", qUtf8Printable(inSrs)) ;
return false;
}

Expand All @@ -75,7 +75,7 @@ namespace scially {
t4326.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
mTransfromer = OGRCreateCoordinateTransformation(&srf, &t4326);
if (!mTransfromer) {
qCritical() << inSrs << "can't transform to WGS84";
qCritical("%s can't transform to WGS84", qUtf8Printable(inSrs));
return false;
}
return true;
Expand All @@ -90,7 +90,7 @@ namespace scially {
auto epsgCode = srs.mid(5).toInt();
auto ret = srf.importFromEPSG(epsgCode);
if (OGRERR_NONE != ret) {
qCritical() << "importFromEPSG failed£º" << srs;
qCritical("importFromEPSG failed£º%s", qUtf8Printable (srs));
return false;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ namespace scially {
{
QStringList srs = inSrs.mid(4).split(",");
if (srs.length() != 2) {
qCritical() << "parse enu:" << inSrs << "failed";
qCritical("parse enu %s failed", qUtf8Printable(inSrs));
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/CesiumMath/SpatialTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace scially {

auto outSRS = dynamic_cast<const SpatialReferenceMatrix*>(&out);
if (!outSRS) {
qCritical() << "not surpport output srs";
qCritical("don't support output srs");
return nullptr;
}

auto inSRSMatrix = dynamic_cast<const SpatialReferenceMatrix*>(&in);
auto inSRSProj = dynamic_cast<const SpatialReferenceProj*>(&in);
if (!inSRSMatrix && !inSRSProj) {
qCritical() << "not surpport input srs";
qCritical("don't support output srs");
return nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commons/TileStorageDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace scially {

QFile writer(outPath);
if (!writer.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
qCritical() << "can't write file:" << file;
qCritical("can't write file %s", qUtf8Printable(file));
return false;
}

Expand Down
28 changes: 2 additions & 26 deletions src/ConvertApp/ConvertApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,8 @@
#include <QCoreApplication>
#include <QTime>

void MessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
QByteArray localMsg = msg.toLocal8Bit();
const char* file = context.file ? context.file : "";
const char* function = context.function ? context.function : "";
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
break;
case QtInfoMsg:
fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
break;
}
}

int main(int argc, char** argv) {
qInstallMessageHandler(MessageOutput);
qSetMessagePattern("[%{type} %{time yyyy-MM-dd h:mm:ss.zzz}] %{file}:%{line} %{message}");
QCoreApplication app(argc, argv);
app.setApplicationVersion(SCIALLY_PROJECT_VERSION);
app.setApplicationName(SCIALLY_PROJECT_NAME);
Expand Down Expand Up @@ -73,6 +49,6 @@ int main(int argc, char** argv) {
}
}

qInfo() << "finish convert in" << beginTime.secsTo(QTime::currentTime()) << "s";
qInfo("finish convert in %d s", beginTime.secsTo(QTime::currentTime()));
return 0;
}
17 changes: 8 additions & 9 deletions src/OSGConvert/OSGFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace scially {
auto tileNode = QSharedPointer<OSGTile>::create(tileFolder.path(), fn, tn);

if (!tileNode->buildIndex()) {
qWarning() << "load" << tileFolder.fileName() << "failed";
qWarning("load tile %s failed", qUtf8Printable(tileFolder.fileName()));
continue;
}

Expand All @@ -46,7 +46,6 @@ namespace scially {
if (size() == 0)
return false;


const osg::Vec3d osgCenter = mInSRS->toWorld(osgBound.center());
mOutSRS.initWithCartesian3(osgCenter);

Expand All @@ -60,27 +59,27 @@ namespace scially {
SpatialReference::Ptr OSGFolder::ReadMetaData(const QString& input) {
QFile metaDataFile(input);
if (!metaDataFile.exists()) {
qCritical() << "can't find metadata.xml";
qCritical("can't find metadata.xml");
return nullptr;
}

QDomDocument metaDataDom;
if (!metaDataDom.setContent(&metaDataFile)) {
qCritical() << "can't parse metadata.xml file";
qCritical("can't parse metadata.xml file");
return nullptr;
}

QDomElement rootElement = metaDataDom.documentElement();
if (rootElement.tagName() != "ModelMetadata") {
qCritical() << "not find ModelMetaData node in metadata.xml";
qCritical("not find ModelMetaData node in metadata.xml");
return nullptr;
}

QDomNodeList srsNodes = rootElement.elementsByTagName("SRS");
QDomNodeList originNodes = rootElement.elementsByTagName("SRSOrigin");

if (srsNodes.isEmpty()) {
qCritical() << "not find SRS node in metadata.xml";
qCritical("not find SRS node in metadata.xml");
return nullptr;
}

Expand Down Expand Up @@ -111,7 +110,7 @@ namespace scially {
for (size_t i = 0; i < size(); i++) {
auto tile = node<OSGTile>(i);
QFuture<bool> f = QtConcurrent::run(&threadPool, [this, tile]() {
qInfo() << tile->tileName() << "tile start convert to b3dm";
qInfo("%s tile start convert to b3dm", qUtf8Printable(tile->tileName()));

auto b3dm = tile->toB3DM(*mSTS, *mStorage);
if(b3dm && b3dm->saveJson(*mStorage, mOutSRS.originENU())) {
Expand All @@ -126,13 +125,13 @@ namespace scially {
for (auto& worker : workFutures) {
worker.waitForFinished();
}
qInfo() << "all tile process finished";
qInfo("all tile process finished");

const BaseTile b = B3DMTile::toBaseTile(mB3dms, mOutSRS.originENU());
BaseTileReadWriter brw;
const QJsonObject obj = brw.writeToJson(b);
if (!mStorage->saveJson("tileset.json", obj)) {
qCritical() << "write tileset.json failed";
qCritical("write tileset.json failed");
}

return mB3dms;
Expand Down
3 changes: 1 addition & 2 deletions src/OSGConvert/OSGLodVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace scially {
parentClassName = geode.getParent(0)->className();

if (parentClassName != "PagedLOD") {
qWarning() << "find a geode not in PagedLOD";
hasContentOutLOD = true;
}

Expand Down Expand Up @@ -89,7 +88,7 @@ namespace scially {
bool OSGLodVisitor::processPagedLod(osg::PagedLOD& lod) {
auto ranges = lod.getRangeList();
if (ranges.empty()) {
qWarning() << lod.getName().c_str() << "is empty rangelist";
qWarning("%s is empty rangelist", lod.getName().data());
return false;
}

Expand Down
Loading

0 comments on commit 6f14903

Please sign in to comment.