Skip to content

Commit

Permalink
generator updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejstrnad committed Aug 25, 2020
1 parent 45393d6 commit a4055e8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ settings
data-generator/debug/
data-generator/.vs/
data-generator/release/
data-generator/output/
4 changes: 4 additions & 0 deletions data-generator/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class Box : public Object {

return list;
}

inline float getVolume() override {
return this->_size.x() * this->_size.y() * this->_size.z();
}
};

#endif // BOX_H
4 changes: 4 additions & 0 deletions data-generator/Ellipsoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Ellipsoid : public Object {

return list;
}

inline float getVolume() override {
return (4.0 / 3.0) * M_PI * (this->_size.x() * this->_size.y() * this->_size.z());
}
};

#endif // ELLIPSOID_H
3 changes: 2 additions & 1 deletion data-generator/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ class Object {
inline uchar getSize() { return _sizeT; }
inline uchar getOrientation() { return _orientation; }
inline QString getName() { return this->_name; }

virtual bool contains(QVector3D point) = 0;
virtual QList<QVector3D> getBoundingBox() = 0;
virtual float getVolume() = 0;
};
// ===================================

Expand Down
4 changes: 4 additions & 0 deletions data-generator/Sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class Sphere : public Object {

return list;
}

inline float getVolume() override {
return (4.0 / 3.0) * M_PI * (this->_radius * this->_radius * this->_radius);
}
};

#endif // SPHERE_H
2 changes: 1 addition & 1 deletion data-generator/data-generator.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.12.2, 2020-08-25T08:36:05. -->
<!-- Written by QtCreator 4.12.2, 2020-08-25T21:34:34. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
36 changes: 27 additions & 9 deletions data-generator/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QVector3D>
#include <QVector4D>
#include <QFile>
#include <QDir>
#include <QtMath>
#include <QDebug>
#include <QDateTime>
Expand Down Expand Up @@ -175,7 +176,7 @@ QList<int> getNeighbors(QList<int>* neighs, Settings* set, int x, int y, int z)

float shortestDistanceToEmptyVoxel(QList<int>* data, Settings* set, int i) {
if ((*data)[i] == 0) {
return (rand() % 1000) / 1000000.0f; // TODO: add some noise
return (rand() % 1000) / 10000000.0f; // TODO: add some noise
}

int x, y, z;
Expand All @@ -192,7 +193,9 @@ float shortestDistanceToEmptyVoxel(QList<int>* data, Settings* set, int i) {
QList<int> neighs;
neighs.append(i);

for (auto n : neighs) {
for (int i = 0; i < neighs.size(); i++) {
auto n = neighs[i];

posFromIndex(n, set, x, y, z);

auto indices = getNeighbors(&neighs, set, x, y, z);
Expand Down Expand Up @@ -354,11 +357,13 @@ void generateData(QList<Object*> objects, Settings* set, QByteArray* data, QByte
out2.setByteOrder(QDataStream::LittleEndian);

qDebug() << "shortest distance computation";
QList<int> dump;
for (int i = 0; i < array.size(); i++) {

float dist = shortestDistanceToEmptyVoxel(&array, set, i);

out2 << dist;
dump.append((int)(dist * 100000));
out2 << (int)(dist * 100000);

if (i % (int)(array.size() * 0.1) == 0) {
qDebug() << i << " voxels done";
Expand Down Expand Up @@ -524,7 +529,8 @@ void generateCSV(QList<Object*> objects, Settings* set)
out << "Orientation" << separator;
out << "X" << separator;
out << "Y" << separator;
out << "Z";
out << "Z" << separator;
out << "Volume";
out << "\r\n";


Expand All @@ -537,7 +543,8 @@ void generateCSV(QList<Object*> objects, Settings* set)
out << o->getOrientation() << separator;
out << o->getPosition().x() << separator;
out << o->getPosition().y() << separator;
out << o->getPosition().z();
out << o->getPosition().z() << separator;
out << o->getVolume() * 1000;
out << "\r\n";
}

Expand All @@ -562,6 +569,7 @@ void generateCSV(QList<Object*> objects, Settings* set)
out << (float)(o->getPosition().x());
out << (float)(o->getPosition().y());
out << (float)(o->getPosition().z());
out << (float)(o->getVolume() * 1000);
}

csvFile.close();
Expand Down Expand Up @@ -642,6 +650,10 @@ QByteArray generateMeta(QList<Object*> objects, Settings* set)
value["type"] = "float";
layout.append(value);

value["name"] = "Volume";
value["type"] = "float";
layout.append(value);

QJsonDocument doc(layout);
return doc.toJson();

Expand Down Expand Up @@ -806,17 +818,23 @@ int main(int argc, char *argv[])
/*set.w = 128;
set.h = 128;
set.d = 128;*/
set.x = 256;
set.y = 256;
set.z = 256;
set.targetCount = 1000;
set.x = 128;
set.y = 128;
set.z = 128;
set.targetCount = 100;
//set.outputType = 3;

// main data generator
QList<Object*> objects = generateObjects(&set);
//QList<Object*> objects = generateObjectsGrid(&set);
qDebug() << objects.size();

auto current = QDir::current();
QDir dir(current.absolutePath() + "/output");
if (!dir.exists()) {
dir.mkdir(current.absolutePath() + "/output");
}

QByteArray volume1, volume2;
generateData(objects, &set, &volume1, &volume2);
set.targetFile = "output/data.raw";
Expand Down

0 comments on commit a4055e8

Please sign in to comment.