Skip to content

Commit

Permalink
Merge branch 'develop' into smurfa
Browse files Browse the repository at this point in the history
  • Loading branch information
hwiedPro authored May 20, 2019
2 parents 1f20aac + 2ba3112 commit 3551368
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 122 deletions.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ IF( MINGW )
ENDIF( MINGW )
endif(MAINGUI_FOUND)

add_executable(${PROJECT_NAME} src/main.cpp ${TARGET_SRC})
add_executable(${PROJECT_NAME} src/main.cpp)
add_library(mars SHARED ${TARGET_SRC})

if(MAINGUI_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion app/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<depend package="simulation/mars/common/gui/data_broker_plotter2" optional="1" />
<depend package="simulation/mars/plugins/SkyDomePlugin" optional="1" />
<depend package="simulation/mars/plugins/CameraGUI" optional="1" />
<depend package="simulation/mars/plugins/PythonMars" optional="1" />
<!--depend package="simulation/mars/plugins/PythonMars" optional="1" /-->
<depend package="simulation/mars/plugins/entity_view" optional="1" />
<depend package="simulation/mars/entity_generation/smurf" optional="1" />
<depend package="simulation/mars/smurf_loader" optional="1" />
Expand Down
3 changes: 3 additions & 0 deletions app/src/MARS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ namespace mars {
//MARS::control->sim->exitMars();
//Convention: print the signal type
}
#ifndef NO_GUI
if(qApp) qApp->quit();
#endif
}

void handle_abort(int signal) {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

void qtExitHandler(int sig) {
mars::app::exit_main(sig);
#ifndef NO_GUI
if(qApp) qApp->quit();
#endif
}

void ignoreSignal(int sig) {
Expand Down Expand Up @@ -88,7 +85,6 @@ int main(int argc, char *argv[]) {
int state;
if(simulation->needQApp) state = app->exec();
else state = simulation->runWoQApp();

delete simulation;
fprintf(stderr, "\n################################\n");
fprintf(stderr, "## everything closed fine ^-^ ##\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
params:
in:
sin: {index: 0, type: float}
cos: {index: 0, type: float}
s: {index: 0, type: vec4}
cos: {index: 1, type: float}
s: {index: 2, type: vec4}
out:
v: {index: 0, type: vec4}
uniforms:
Expand Down
43 changes: 25 additions & 18 deletions common/graphics/osg_material_manager/src/OsgMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@
#include <osg/CullFace>

#ifdef WIN32
#include <cv.h>
#include <highgui.h>
#include <opencv2/opencv.hpp>
#else
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/opencv.hpp>
#endif

#include <cmath>
Expand Down Expand Up @@ -756,37 +754,46 @@ namespace osg_material_manager {
}

osg::Texture2D* OsgMaterial::loadTerrainTexture(std::string filename) {
IplImage* img=cvLoadImage(filename.c_str(), -1);
cv::Mat img=cv::imread(filename, cv::IMREAD_ANYDEPTH);
osg::Texture2D *texture = NULL;
if(img) {
if(img.data) {
texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
texture->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP);
osg::Image* image = new osg::Image();
image->allocateImage(img->width, img->height,
image->allocateImage(img.cols, img.rows,
1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV);
assert(img->width = img->height);
terrainDimUniform->set((int)img->width);
CvScalar s;
assert(img.cols == img.rows);
if(img.cols != img.rows or img.channels() != 1) {
fprintf(stderr, "ERROR: bad heightmap loaded: w=%d h=%d c=%d\n",
img.cols, img.rows, img.channels());
return texture;
}

terrainDimUniform->set((int)img.cols);
cv::Scalar s;
int depth = img.depth();
int v;
double imageMaxValue = pow(2., img->depth);
double imageMaxValue = pow(2., depth);
double s256 = 1./256;
for(int x=0; x<img->width; ++x) {
for(int y=0; y<img->width; ++y) {
s=cvGet2D(img,y,x);
if(img->depth == 16) {
v = floor(s.val[0]*s256);
for(int x=0; x<img.cols; ++x) {
for(int y=0; y<img.rows; ++y) {
//s=cvGet2D(img,y,x);
if(depth == CV_16U) {
s = img.at<ushort>(y,x);
v = floor(s[0]*s256);
if(v < 0) v = 0;
if(v>255) v = 255;
image->data(y, x)[0] = (char)v;
v = (int)s.val[0] % 256;
v = (int)s[0] % 256;
if(v < 0) v = 0;
if(v>255) v = 255;
image->data(y, x)[1] = (char)v;
}
else {
s = img.at<uchar>(y,x);
image->data(y, x)[0] = (char)s.val[0];
image->data(y, x)[1] = 0;
}
Expand All @@ -797,7 +804,7 @@ namespace osg_material_manager {
//osgDB::writeImageFile(*image, "da.png");

texture->setImage(image);
cvReleaseImage(&img);
img.release();//cvReleaseImage(&img);
}
return texture;
}
Expand Down
43 changes: 26 additions & 17 deletions graphics/src/gui_helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
#endif

#ifdef WIN32
#include <cv.h>
#include <highgui.h>
#include <opencv2/opencv.hpp>
#else
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/opencv.hpp>
#endif

#include <mars/utils/mathUtils.h>
Expand Down Expand Up @@ -569,28 +567,38 @@ namespace mars {
void GuiHelper::readPixelData(mars::interfaces::terrainStruct *terrain) {

#if !defined (WIN32) && !defined (__linux__)
IplImage* img=0;
cv::Mat img;

img=cvLoadImage(terrain->srcname.data(), -1);
if(img) {
terrain->width = img->width;
terrain->height = img->height;
fprintf(stderr, "w h = %d %d\n", img->width, img->height);
img=cv::imread(terrain->srcname, cv::IMREAD_ANYDEPTH);
if(img.data) {
terrain->width = img.cols;
terrain->height = img.rows;
fprintf(stderr, "w h = %d %d\n", img.cols, img.rows);
terrain->pixelData = (double*)calloc((terrain->width*
terrain->height),
sizeof(double));


CvScalar s;
if(img.channels() != 1) {
fprintf(stderr, "Error: loading heightmap data. Only single channel grayscale images can be loaded!\n");
return;
}
cv::Scalar s;
int count = 0;
double imageMaxValue = pow(2., img->depth);
int depth = img.depth();
double imageMaxValue = pow(2., 8);
if(depth==CV_16U) {
imageMaxValue = pow(2., 16);
}
//for(int y=0; y<terrain->height; y++) {
//for(int x=terrain->width-1; x>=0; x--) {
for(int y=terrain->height-1; y>=0; y--) {
for(int x=0; x<terrain->width; x++) {

s=cvGet2D(img,y,x);
terrain->pixelData[count++] = ((double)s.val[0])/(imageMaxValue-1);
if(depth == CV_16U) {
s = img.at<ushort>(y,x);
} else {
s = img.at<uchar>(y,x);
}
terrain->pixelData[count++] = ((double)s[0])/(imageMaxValue-1);
// if(y==0 || y == terrain->height-1 ||
// x==0 || x == terrain->width-1)
// terrain->pixelData[count-1] -= 0.002;
Expand All @@ -599,7 +607,8 @@ namespace mars {

}
}
cvReleaseImage(&img);
img.release();
//cvReleaseImage(&img);
}

#else
Expand Down
57 changes: 37 additions & 20 deletions gui/src/dialogs/CaptureWindow/ImageProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
#include "ImageProcess.h"
#include <cstdio>

#ifdef WIN32
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#else
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#endif

#ifndef CV_FOURCC_MACRO
#define CV_FOURCC cv::VideoWriter::fourcc
#endif

namespace mars {
namespace gui {

Expand All @@ -30,7 +42,6 @@ namespace mars {
start();
state = 1;
width = height = 0;
writer = 0;
this->framerate = framerate;
fprintf(stderr, "created ImagePorcess\n");
}
Expand Down Expand Up @@ -63,8 +74,8 @@ namespace mars {
uchar *data = 0;
uchar *dest, *src;
QString num;
IplImage *cvImage = 0;

cv::Mat cvImage;
cv::VideoWriter writer;
imageCount = 0;
file_count = 0;

Expand All @@ -82,24 +93,24 @@ namespace mars {
newImage = imageList[0];
imageList.erase(imageList.begin());
listMutex.unlock();

if(width == 0) {
width = newImage.width;
height = newImage.height;
writer = cvCreateVideoWriter(qPrintable(file),
//-1, framerate,
CV_FOURCC('X', 'V', 'I', 'D'), framerate,
//CV_FOURCC('M', 'J', 'P', 'G'), framerate,
cvSize(width, height), 1);
cvImage = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
writer.open(qPrintable(file),
//-1, framerate,
CV_FOURCC('X', 'V', 'I', 'D'), framerate,
//cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), framerate,
cv::Size(width, height), 1);
cvImage = cv::Mat(cv::Size(width, height), CV_8UC3);
data = (uchar*)malloc(width*height*3);
cvImage->imageData = (char*)data;
cvImage.data = data;
}
// convert to standard rgb image
for (int i=0; i<newImage.height; ++i) {
for(int k=0; k<newImage.width; ++k) {
dest = data + ((newImage.height-1)*(newImage.width)*3-
i*newImage.width*3 + k*3);
dest = cvImage.data + ((newImage.height-1)*(newImage.width)*3-
i*newImage.width*3 + k*3);

src = (uchar*)newImage.data + (i*newImage.width*4) + k*4;

Expand All @@ -108,10 +119,14 @@ namespace mars {
}

// save new Image
if(writer) {
cvWriteFrame(writer, cvImage);
if(writer.isOpened()) {
fprintf(stderr, ".");
writer.write(cvImage);
++imageCount;
}
else {
fprintf(stderr, "ERROR: writer not opened!\n");
}

// free memory
free(newImage.data);
Expand All @@ -121,11 +136,13 @@ namespace mars {
msleep(4);
}
}

// clean up
if(writer) cvReleaseVideoWriter(&writer);
if(cvImage) cvReleaseImageHeader(&cvImage);
if(data) free(data);

if(writer.isOpened()) writer.release();
//if(cvImage.data) cvImage.release();
if(data) {
free(data);
data = NULL;
}
}

} // end of namespace gui
Expand Down
9 changes: 0 additions & 9 deletions gui/src/dialogs/CaptureWindow/ImageProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
#include <QMutex>
#include <vector>

#ifdef WIN32
#include <cv.h>
#include <highgui.h>
#else
#include <opencv/cv.h>
#include <opencv/highgui.h>
#endif

namespace mars {
namespace gui {

Expand Down Expand Up @@ -64,7 +56,6 @@ namespace mars {
int file_count;
int width, height;
int framerate;
CvVideoWriter *writer;
};

} // end of namespace gui
Expand Down
2 changes: 2 additions & 0 deletions plugins/PythonMars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pkg_check_modules(PKGCONFIG REQUIRED
osg_lines
osg_material_manager
mars_sim
mars_app
)
include_directories(${PKGCONFIG_INCLUDE_DIRS})
link_directories(${PKGCONFIG_LIBRARY_DIRS})
Expand Down Expand Up @@ -55,6 +56,7 @@ if (APPLE)
set(PYTHON_LIBRARY "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python")
set(PYTHON_INCLUDE_DIR "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7" "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include")
endif (APPLE)
#add_definitions(-DPYTHON3)
set(Python_ADDITIONAL_VERSIONS "2.7")
find_package(PythonLibs REQUIRED)

Expand Down
1 change: 1 addition & 0 deletions plugins/PythonMars/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<depend package="simulation/mars/common/data_broker" />
<depend package="simulation/mars/interfaces" />
<depend package="simulation/mars/sim" />
<depend package="simulation/mars/app" />
<depend package="simulation/mars/common/graphics/osg_lines" />
<depend package="simulation/mars/common/graphics/osg_points" />
<depend package="simulation/mars/common/graphics/osg_material_manager" />
Expand Down
Loading

0 comments on commit 3551368

Please sign in to comment.