22#include "Inventor/nodes/SoMaterial.h"
23#include <Inventor/nodes/SoPerspectiveCamera.h>
24#include <Inventor/nodes/SoOrthographicCamera.h>
25#include <Inventor/nodes/SoGroup.h>
26#include <Inventor/nodes/SoNurbsCurve.h>
27#include <Inventor/nodes/SoCoordinate4.h>
29#include <Inventor/SoPath.h>
30#include <Inventor/SoOffscreenRenderer.h>
31#include "Inventor/Qt/SoQtRenderArea.h"
32#include <Inventor/actions/SoSearchAction.h>
33#include <Inventor/SoDB.h>
34#include <Inventor/actions/SoWriteAction.h>
36#include <Inventor/nodes/SoLineSet.h>
37#include <Inventor/nodes/SoVertexProperty.h>
40#include <Inventor/VRMLnodes/SoVRMLGroup.h>
41#include <Inventor/actions/SoToVRML2Action.h>
49#include <QtCoreVersion>
55 ucharAddress(
auto * pv){
56 return reinterpret_cast<unsigned char *
>(
pv);
66 static void bwtorgba(
unsigned char *b,
unsigned char *l,
int n)
77 static void latorgba(
unsigned char *b,
unsigned char *
a,
unsigned char *l,
int n)
89 unsigned char *b,
unsigned char *l,
int n)
96 l += 4; ++
r; ++g; ++b;
101 unsigned char *b,
unsigned char *
a,
unsigned char *l,
int n)
108 l += 4; ++
r; ++g; ++b; ++
a;
131 *array = std::byteswap (*array);
140 const bool swapFlag = std::endian::native == std::endian::little;
143 fprintf(stderr,
"Out of memory!\n");
146 if (!(image->file = fopen(fileName,
"rb"))) {
152 int bytesRead = fread(image, 1, 12, image->file);
154 if (bytesRead != 12) {
155 fprintf(stderr,
"fread failed!\n");
166 image->imagic = std::byteswap (image->imagic);
167 image->type = std::byteswap (image->type);
168 image->dim = std::byteswap (image->dim);
169 image->xsize = std::byteswap (image->xsize);
170 image->ysize = std::byteswap (image->ysize);
171 image->zsize = std::byteswap (image->zsize);
175 const unsigned int colourBuffSize=image->xsize*256u;
176 image->tmp = ucharAddress(malloc(colourBuffSize));
177 image->tmpR = ucharAddress(malloc(colourBuffSize));
178 image->tmpG = ucharAddress(malloc(colourBuffSize));
179 image->tmpB = ucharAddress(malloc(colourBuffSize));
180 if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
181 image->tmpB == NULL) {
182 fprintf(stderr,
"Out of memory!\n");
187 if ((image->type & 0xFF00) == 0x0100) {
188 size_t x = ((size_t)image->ysize * (size_t)image->zsize) *
sizeof(
unsigned);
191 image->rowStart = (
unsigned *)malloc(
x);
192 image->rowSize = (
int *)malloc(
x);
193 if (image->rowStart == NULL || image->rowSize == NULL) {
194 fprintf(stderr,
"Out of memory!\n");
197 image->rleEnd = 512 + (2 *
x);
198 const int fseekRetVal= fseek(image->file, 512, SEEK_SET);
199 if (fseekRetVal !=0){
200 fprintf(stderr,
"Something very wrong with fseek near line 205 of VP1QtInventorUtils.cxx");
202 size_t bytesRead = 0;
203 bytesRead = fread(image->rowStart, 1,
x, image->file);
205 bytesRead = fread(image->rowSize, 1,
x, image->file);
210 ConvertLong((
unsigned *)image->rowSize,
x/(
int)
sizeof(
int));
213 image->rowStart = NULL;
214 image->rowSize = NULL;
226 free(image->rowSize);
227 free(image->rowStart);
232 unsigned char *buf,
int y,
int z)
234 unsigned char *iPtr, *oPtr,
pixel;
238 if ((image->type & 0xFF00) == 0x0100) {
240 int okseek = fseek(image->file, (
long)image->rowStart[
y+
z*image->ysize], SEEK_SET);
241 int okread = fread(image->tmp, 1, (
unsigned int)image->rowSize[
y+
z*image->ysize],
266 const unsigned int yDim(
y*image->xsize), zDim(
z*image->xsize*image->ysize);
267 int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
270 size_t bytesRead = 0;
271 bytesRead = fread(buf, 1, image->xsize, image->file);
277 std::cout <<
"Warning! ImageGetRow() - no 'image'..." << std::endl;
283 unsigned *
base, *lptr;
284 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
293 (*width)=image->xsize;
294 (*height)=image->ysize;
295 (*components)=image->zsize;
296 const unsigned int imageWidth = image->xsize;
297 const unsigned int imageHeight = image->ysize;
298 const unsigned int uintSize(
sizeof(
unsigned)), ucharSize(
sizeof(
unsigned char));
299 const unsigned int colourBufSize=imageWidth*ucharSize;
300 base =
reinterpret_cast<unsigned *
>(malloc(imageWidth*imageHeight*uintSize));
301 rbuf = ucharAddress(malloc(colourBufSize));
302 gbuf = ucharAddress(malloc(colourBufSize));
303 bbuf = ucharAddress(malloc(colourBufSize));
304 abuf = ucharAddress(malloc(colourBufSize));
305 if(!
base || !rbuf || !gbuf || !bbuf) {
308 if (rbuf) free(rbuf);
309 if (gbuf) free(gbuf);
310 if (bbuf) free(bbuf);
311 if (abuf) free(abuf);
315 for (
y=0;
y<image->ysize; ++
y) {
316 if (image->zsize>=4) {
323 rgbatorgba(rbuf,gbuf,bbuf,abuf,ucharAddress(lptr),image->xsize);
324 lptr += image->xsize;
325 }
else if(image->zsize==3) {
329 rgbtorgba(rbuf,gbuf,bbuf,ucharAddress(lptr),image->xsize);
330 lptr += image->xsize;
331 }
else if(image->zsize==2) {
334 latorgba(rbuf,abuf,ucharAddress(lptr),image->xsize);
335 lptr += image->xsize;
338 bwtorgba(rbuf,ucharAddress(lptr),image->xsize);
339 lptr += image->xsize;
348 return (
unsigned *)
base;
403 constexpr int maxheight(10'000);
404 constexpr int maxwidth(10'000);
405 auto inbounds = [](
int w,
int h)->
bool{
406 return (w>0 and w<maxwidth) and (
h>0 and
h<maxheight);
409 if( not inbounds(
width, height)){
410 std::cout <<
"VP1QtInventorUtils::imageFromRGBFile - read_texture failed?" << std::endl;
412 height = std::clamp(height, 0, maxheight);
414 unsigned char * data =
reinterpret_cast<unsigned char*
>(imagedata);
416 QImage im(
width,height, ( components <= 3 ? QImage::Format_RGB32 : QImage::Format_ARGB32 ) );
419 for (;
y<height; ++
y) {
422 im.setPixel (
x, height-
y-1, QColor(
static_cast<int>(data[
index]),
static_cast<int>(data[
index+1]),
static_cast<int>(data[
index+2]),
static_cast<int>(data[
index+3]) ).rgb() );
434 bool transparent_background,
double actualRenderedSizeFact )
447 if (actualRenderedSizeFact!=1.0&&!transparent_background) {
449 static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
450 static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
453 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
456 if (transparent_background) {
461 SbColor save_bgd = ra->getBackgroundColor();
462 SbBool save_redraw = ra->isAutoRedraw();
464 ra->setAutoRedraw(
false);
467 QImage im_black_bgd, im_white_bgd;
468 if (actualRenderedSizeFact==1.0) {
469 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
470 im_black_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
471 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
472 im_white_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
474 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
475 im_black_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
476 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
477 im_white_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
480 ra->setBackgroundColor(save_bgd);
481 ra->setAutoRedraw(save_redraw);
483 if (actualRenderedSizeFact==1.0)
487 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
504 SoNode *rootOverlay = ra->getOverlaySceneGraph();
509 SbViewportRegion myViewport;
510 myViewport.setWindowSize(SbVec2s(pixels_x,pixels_y));
512 QString tmppath(QDir::tempPath());
513 if (!tmppath.endsWith(QDir::separator()))
514 tmppath+=QDir::separator();
515 tmppath +=
"vp1tmpfileXXXXXX.rgb";
516 std::string stmppath = tmppath.toStdString();
517 int tmpfd = mkstemps (stmppath.data(), 4);
519 VP1Msg::message(
"ERROR - Snapshot: could not create a temporary image file in " + QDir::tempPath());
522 FILE* tmpf = fdopen (tmpfd,
"w");
525 QFile::remove(QString::fromStdString(stmppath));
526 VP1Msg::message(
"ERROR - Snapshot: could not open the temporary image stream.");
529 QString tmpfile (stmppath.c_str());
532 SoOffscreenRenderer *myRenderer =
new SoOffscreenRenderer(myViewport);
535 myRenderer->setBackgroundColor(ra->getBackgroundColor());
538 myRenderer->setComponents(SoOffscreenRenderer::RGB_TRANSPARENCY);
539 myRenderer->getGLRenderAction()->setTransparencyType(ra->getTransparencyType());
543 SbBool smoothing;
int numPasses;
544 ra->getAntialiasing (smoothing, numPasses);
545 myRenderer->getGLRenderAction()->setSmoothing (smoothing);
546 myRenderer->getGLRenderAction()->setNumPasses(numPasses);
553 if (!myRenderer->render(root)) {
554 VP1Msg::message(
"ERROR - Snapshot: Coin offscreen scene rendering failed. "
555 "Check GLX support on this display; restart with COIN_DEBUG_GLGLUE=1 for diagnostics.");
558 QFile::remove(tmpfile);
566 bool okOver = myRenderer->render(rootOverlay);
568 VP1Msg::message(
"ERROR - Snapshot: Coin offscreen overlay rendering failed.");
571 QFile::remove(tmpfile);
581 if (!myRenderer->writeToRGB(tmpf)) {
582 VP1Msg::message(
"ERROR - Snapshot: Coin could not write the temporary RGB image.");
584 if (QFile::exists(tmpfile))
585 QFile(tmpfile).remove();
598 VP1Msg::message(
"ERROR - Snapshot: could not decode the temporary RGB image.");
602 if (QFile::exists(tmpfile))
603 QFile(tmpfile).remove();
612 bool transparent_background,
double actualRenderedSizeFact )
614 return QPixmap::fromImage(
renderToImage(ra, pixels_x, pixels_y, transparent_background, actualRenderedSizeFact));
620 if (im_black_bgd.isNull()||im_white_bgd.isNull()||im_black_bgd.size()!=im_white_bgd.size())
623 QImage im(im_black_bgd.size(),QImage::Format_ARGB32);
625 int width = im.width();
626 int height = im.height();
627 QRgb white = qRgba(255,255,255,255);
628 QRgb
black = qRgba(0,0,0,255);
631 for (
int y = 0;
y < height; ++
y) {
632 if (im_black_bgd.pixel(
x,
y)==im_white_bgd.pixel(
x,
y)) {
633 im.setPixel(
x,
y,im_white_bgd.pixel(
x,
y));
634 }
else if (im_black_bgd.pixel(
x,
y)==
black&&im_white_bgd.pixel(
x,
y)==white) {
635 im.setPixel(
x,
y,Qt::transparent);
638 QColor pix_b = QColor(im_black_bgd.pixel(
x,
y));
639 QColor pix_w = QColor(im_white_bgd.pixel(
x,
y));
640 qreal alpha = 1.0 - pix_w.redF() + pix_b.redF();
642 im.setPixel(
x,
y,Qt::transparent);
644 im.setPixel(
x,
y,qRgba(
static_cast<int>(pix_b.redF()/alpha*255+0.5),
645 static_cast<int>(pix_b.greenF()/alpha*255+0.5),
646 static_cast<int>(pix_b.blueF()/alpha*255+0.5),
647 static_cast<int>(alpha*255+0.5)));
659 return SoGLRenderAction::DELAYED_BLEND;
665 QList<SoGLRenderAction::TransparencyType> l;
666 l << SoGLRenderAction::NONE
667 << SoGLRenderAction::SCREEN_DOOR
668 << SoGLRenderAction::ADD
669 << SoGLRenderAction::DELAYED_ADD
670 << SoGLRenderAction::SORTED_OBJECT_ADD
671 << SoGLRenderAction::BLEND
672 << SoGLRenderAction::DELAYED_BLEND
673 << SoGLRenderAction::SORTED_OBJECT_BLEND
674 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD
675 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND
676 << SoGLRenderAction::SORTED_LAYERS_BLEND;
684 case SoGLRenderAction::SCREEN_DOOR:
return 0;
685 case SoGLRenderAction::ADD:
return 1;
686 case SoGLRenderAction::DELAYED_ADD:
return 2;
687 case SoGLRenderAction::SORTED_OBJECT_ADD:
return 3;
688 case SoGLRenderAction::BLEND:
return 4;
689 case SoGLRenderAction::DELAYED_BLEND:
return 5;
690 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return 6;
691 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return 7;
692 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return 8;
693 case SoGLRenderAction::NONE:
return 9;
694 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return 10;
696 VP1Msg::messageDebug(
"VP1QtInventorUtils::transparencyTypeToInt ERROR: Unknown transparency type");
704 case 0:
return SoGLRenderAction::SCREEN_DOOR;
705 case 1:
return SoGLRenderAction::ADD;
706 case 2:
return SoGLRenderAction::DELAYED_ADD;
707 case 3:
return SoGLRenderAction::SORTED_OBJECT_ADD;
708 case 4:
return SoGLRenderAction::BLEND;
709 case 5:
return SoGLRenderAction::DELAYED_BLEND;
710 case 6:
return SoGLRenderAction::SORTED_OBJECT_BLEND;
711 case 7:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD;
712 case 8:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND;
713 case 9:
return SoGLRenderAction::NONE;
714 case 10:
return SoGLRenderAction::SORTED_LAYERS_BLEND;
717 return SoGLRenderAction::DELAYED_BLEND;
726 case SoGLRenderAction::DELAYED_BLEND:
return "Delayed blend";
break;
727 case SoGLRenderAction::SCREEN_DOOR:
return "Screen door";
break;
728 case SoGLRenderAction::ADD:
return "Add";
break;
729 case SoGLRenderAction::DELAYED_ADD:
return "Delayed add";
break;
730 case SoGLRenderAction::SORTED_OBJECT_ADD:
return "Sorted object add";
break;
731 case SoGLRenderAction::BLEND:
return "Blend (Best for Geo volumes)";
break;
732 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return "Sorted object blend (Best for physics objects: jets, tracks, ...)";
break;
733 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return "Sorted object sorted triangle add";
break;
734 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return "Sorted object sorted triangle blend";
break;
735 case SoGLRenderAction::NONE:
return "None";
break;
736 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return "Sorted layers blend";
break;
747 QByteArray byteArray;
748 QBuffer buffer(&byteArray);
749 buffer.open(QIODevice::WriteOnly);
750 QDataStream out(&buffer);
755 rot.getValue (q0,q1,q2,q3);
765 +QString::number(q0)+
", "+QString::number(q1)+
", "
766 +QString::number(q2)+
", "+QString::number(q3)+
")");
779 buffer.open(QIODevice::ReadOnly);
780 QDataStream state(&buffer);
784 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
792 rot.setValue (q0,q1,q2,q3);
797 +QString::number(q0)+
", "+QString::number(q1)+
", "
798 +QString::number(q2)+
", "+QString::number(q3)+
")");
810 rot.setValue (q0,q1,q2,q3);
815 +QString::number(q0)+
", "+QString::number(q1)+
", "
816 +QString::number(q2)+
", "+QString::number(q3)+
")");
830 QByteArray byteArray;
831 QBuffer buffer(&byteArray);
832 buffer.open(QIODevice::WriteOnly);
833 QDataStream out(&buffer);
845 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
858 buffer.open(QIODevice::ReadOnly);
859 QDataStream state(&buffer);
863 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
875 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
890 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
907 QByteArray byteArray;
908 QBuffer buffer(&byteArray);
909 buffer.open(QIODevice::WriteOnly);
910 QDataStream out(&buffer);
914 SbRotation camrot = cam.orientation.getValue();
916 SbVec3f campos = cam.position.getValue();
918 float f_aspectRatio(cam.aspectRatio.getValue());
919 float f_nearDistance(cam.nearDistance.getValue());
920 float f_farDistance(cam.farDistance.getValue());
921 float f_focalDistance(cam.focalDistance.getValue());
922 out << (double)f_aspectRatio;
923 out << (double)f_nearDistance;
924 out << (double)f_farDistance;
925 out << (double)f_focalDistance;
928 switch (cam.viewportMapping.getValue()) {
929 case SoCamera::CROP_VIEWPORT_FILL_FRAME: viewportmap = 0;
break;
930 case SoCamera::CROP_VIEWPORT_LINE_FRAME: viewportmap = 1;
break;
931 case SoCamera::CROP_VIEWPORT_NO_FRAME: viewportmap = 2;
break;
932 case SoCamera::ADJUST_CAMERA: viewportmap = 3;
break;
933 case SoCamera::LEAVE_ALONE: viewportmap = 4;
break;
939 if (cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId()))
941 else if (cam.getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId()))
946 out << (double)static_cast<const SoPerspectiveCamera*>(&cam)->heightAngle.getValue();
947 }
else if (camtype==1) {
948 out << (double)static_cast<const SoOrthographicCamera*>(&cam)->height.getValue();
957 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
958 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
959 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
960 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
961 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
963 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
966 +QString::number(
static_cast<const SoPerspectiveCamera*
>(&cam)->heightAngle.getValue()));
969 +QString::number(
static_cast<const SoOrthographicCamera*
>(&cam)->height.getValue()));
980 if (ba==QByteArray())
985 buffer.open(QIODevice::ReadOnly);
986 QDataStream state(&buffer);
990 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
993 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
996 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
999 bool save = cam.enableNotify(
false);
1001 cam.orientation.setValue(rot);
1002 cam.position.setValue(pos);
1004 float f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
1006 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
1007 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
1008 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
1009 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
1013 switch (viewportmap) {
1014 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
1015 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
1016 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
1017 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
1018 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1022 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1027 float f_orthopersp_heightpar(-999);
1030 if (!passedcameraisperspective)
1032 state >> f_orthopersp_heightpar;
1033 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1034 }
else if (camtype==1) {
1036 if (passedcameraisperspective)
1038 state >> f_orthopersp_heightpar;
1039 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1043 cam.enableNotify(
true);
1051 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1052 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1053 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1054 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1055 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1057 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1060 +QString::number(f_orthopersp_heightpar));
1063 +QString::number(f_orthopersp_heightpar));
1071 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
1074 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
1077 bool save = cam.enableNotify(
false);
1079 cam.orientation.setValue(rot);
1080 cam.position.setValue(pos);
1082 double f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
1084 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
1085 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
1086 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
1087 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
1091 switch (viewportmap) {
1092 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
1093 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
1094 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
1095 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
1096 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1100 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1105 double f_orthopersp_heightpar(-999);
1108 if (!passedcameraisperspective)
1110 state >> f_orthopersp_heightpar;
1111 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1112 }
else if (camtype==1) {
1114 if (passedcameraisperspective)
1116 state >> f_orthopersp_heightpar;
1117 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1121 cam.enableNotify(
true);
1129 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1130 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1131 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1132 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1133 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1135 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1138 +QString::number(f_orthopersp_heightpar));
1141 +QString::number(f_orthopersp_heightpar));
1146 cam.unrefNoDelete();
1154 return SbColor( col.red()/255.0, col.green()/255.0, col.blue()/255.0 );
1161 col.getValue(
r,g,b);
1162 return QColor::fromRgbF(
r,g,b );
1168 if (!m||m->ambientColor.getNum()!=1
1169 ||m->diffuseColor.getNum()!=1
1170 ||m->specularColor.getNum()!=1
1171 ||m->emissiveColor.getNum()!=1
1172 ||m->transparency.getNum()!=1
1173 ||m->shininess.getNum()!=1) {
1175 "Passed material must have exactly one value in each of the 6 fields!!");
1176 return QByteArray();
1181 QByteArray byteArray;
1182 QBuffer buffer(&byteArray);
1183 buffer.open(QIODevice::WriteOnly);
1184 QDataStream out(&buffer);
1187 out << QString(
"somat_v1_begin");
1192 out << (double)m->shininess[0];
1193 out << (double)m->transparency[0];
1194 out << QString(
"somat_end");
1206 if (!m||m->ambientColor.getNum()!=1
1207 ||m->diffuseColor.getNum()!=1
1208 ||m->specularColor.getNum()!=1
1209 ||m->emissiveColor.getNum()!=1
1210 ||m->transparency.getNum()!=1
1211 ||m->shininess.getNum()!=1) {
1213 "Passed material must have exactly one value in each of the 6 fields!!");
1218 QBuffer buffer(&ba);
1219 buffer.open(QIODevice::ReadOnly);
1220 QDataStream stream(&buffer);
1222 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
1225 QString
str; stream >>
str;
1226 if (
str!=
"somat_v1_begin")
1229 QColor ambientcol; stream >> ambientcol;
1230 if (!ambientcol.isValid())
1233 QColor diffusecol; stream >> diffusecol;
1234 if (!diffusecol.isValid())
1237 QColor specularcol; stream >> specularcol;
1238 if (!specularcol.isValid())
1241 QColor emissivecol; stream >> emissivecol;
1242 if (!emissivecol.isValid())
1245 if(ba.size()==106) {
1247 float shininess; stream >> shininess;
1248 if (shininess<0.0f||shininess>1.0f)
1251 float transparency; stream >> transparency;
1252 if (transparency<0.0f||transparency>1.0f)
1256 if (
str!=
"somat_end")
1262 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1263 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1264 m->specularColor.setValue(
qcol2sbcol(specularcol));
1265 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1266 m->shininess.setValue(shininess);
1267 m->transparency.setValue(transparency);
1271 double shininess; stream >> shininess;
1272 if (shininess<0.0||shininess>1.0)
1275 double transparency; stream >> transparency;
1276 if (transparency<0.0||transparency>1.0)
1280 if (
str!=
"somat_end")
1286 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1287 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1288 m->specularColor.setValue(
qcol2sbcol(specularcol));
1289 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1290 m->shininess.setValue(shininess);
1291 m->transparency.setValue(transparency);
1300 SoGroup* grp =
new SoGroup;
1303 SoCoordinate4 *
coord =
new SoCoordinate4;
1304 const double invsqrttwo=0.707106781186547;
1307 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1308 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1309 coord->point.set1Value(icoord++,SbVec4f(0,1*radius,0,1));
1310 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1311 coord->point.set1Value(icoord++,SbVec4f(-1*radius,0,0,1));
1312 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1313 coord->point.set1Value(icoord++,SbVec4f(0,-1*radius,0,1));
1314 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1315 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1317 SoNurbsCurve * curve =
new SoNurbsCurve;
1318 curve->numControlPoints = icoord;
1322 curve->knotVector.set1Value(iknot++,0);
1323 curve->knotVector.set1Value(iknot++,0);
1324 curve->knotVector.set1Value(iknot++,0);
1325 curve->knotVector.set1Value(iknot++,1);
1326 curve->knotVector.set1Value(iknot++,1);
1327 curve->knotVector.set1Value(iknot++,2);
1328 curve->knotVector.set1Value(iknot++,2);
1329 curve->knotVector.set1Value(iknot++,3);
1330 curve->knotVector.set1Value(iknot++,3);
1331 curve->knotVector.set1Value(iknot++,4);
1332 curve->knotVector.set1Value(iknot++,4);
1333 curve->knotVector.set1Value(iknot++,4);
1334 grp->addChild(
coord);
1335 grp->addChild(curve);
1337 grp->unrefNoDelete();
1344 SoVertexProperty *vertices =
new SoVertexProperty();
1347 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1348 for (
int i = 1; i < numnodes; i++)
1350 vertices->vertex.set1Value(iver++,
1351 cos(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusX,
1352 sin(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusY,0.0);
1354 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1356 SoLineSet * ellipse =
new SoLineSet();
1357 ellipse->numVertices = iver;
1358 ellipse->vertexProperty = vertices;
1366 if (!path||!commonBranchPoint||!newtail)
1370 sa.setInterest(SoSearchAction::FIRST);
1371 sa.setNode(newtail);
1372 sa.apply(commonBranchPoint);
1375 SoPath * newpath = sa.getPath();
1379 for (
int i=0;i<path->getLength();++i) {
1380 if (path->getNode(i)==commonBranchPoint) {
1382 path->truncate(i+1);
1387 path->append(newpath);
1408 buffer = (
char *)malloc(1024);
1412 SoWriteAction wa(&out);
1423 SoToVRML2Action vwa;
1426 SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
1429 out.openFile(qPrintable(filename));
1430 out.setHeaderString(
"#VRML V2.0 utf8");
1431 SoWriteAction wra(&out);
1446 root->unrefNoDelete();
1448 QFile data(filename);
1449 if (data.open(QFile::WriteOnly | QFile::Truncate)) {
1450 QTextStream out(&data);
1451#if QTCORE_VERSION >= 0x050E00
1452 out << s << Qt::endl;
1467 if (!in.openFile(filename.toStdString().c_str()))
1469 return SoDB::readAll(&in);
1481 root->unrefNoDelete();
1499 const double& brightness,
const double& transp )
1507 const double& brightness,
const double& transp )
1509 setMatColor( m, col.redF(), col.greenF(), col.blueF(), brightness, transp);
1542 "purpose of getting supported line widths and point sizes!");
1546 SbVec2f range;
float granularity;
1547 ra->getLineWidthLimits(range, granularity);
1549 range.getValue(
a,b);
1553 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined line widths supported by hardware (min,max,granularity) = ("
1555 ra->getPointSizeLimits(range, granularity);
1556 range.getValue(
a,b);
1560 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined point sizes supported by hardware (min,max,granularity) = ("
1587 slider->setRange(0,nsteps);
1588 slider->setSingleStep(1);
1589 slider->setPageStep(stepsPerUnit);
1599 int nsteps = std::min(1000,std::max<int>(0,
1601 int stepsPerUnit = std::min(nsteps,std::max<int>(1,
1603 slider->setRange(0,nsteps);
1604 slider->setSingleStep(1);
1605 slider->setPageStep(stepsPerUnit);
1615 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1617 if (slider->value()!=itarget)
1618 slider->setValue(itarget);
1628 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1630 if (slider->value()!=itarget)
1631 slider->setValue(itarget);
std::vector< size_t > vec
size_t size() const
Number of registered mappings.
Header file for AthHistogramAlgorithm.
SoQtViewer::StereoType getStereoTypeSlot(void) const
float getStereoOffsetSlot()
virtual SoNode * getSceneGraph()
static void messageVerbose(const QString &)
static void messageDebug(const QString &)
static void message(const QString &, IVP1System *sys=0)
static double allowedPointSizeMin
static double allowedLineWidthMax
static void buffer_vrmlwriteaction(SoNode *root, const QString &filename)
static QString buffer_writeaction(SoNode *root)
static unsigned * read_texture(const char *name, int *width, int *height, int *components)
static void * buffer_realloc(void *bufptr, size_t size)
static void rgbatorgba(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a, unsigned char *l, int n)
static bool lineWidthAndPointSizeNeedsInit
static double allowedLineWidthMin
static double allowedPointSizeGranularity
static double allowedLineWidthGranularity
static void ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z)
static void latorgba(unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void rgbtorgba(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *l, int n)
struct VP1QtInventorUtils::Imp::_ImageRec ImageRec
static double allowedPointSizeMax
static size_t buffer_size
static QImage constructImageWithTransparentBackground(const QImage &im_black_bgd, const QImage &image_white_bgd)
static void ImageClose(ImageRec *image)
static void bwtorgba(unsigned char *b, unsigned char *l, int n)
static void ConvertLong(unsigned *array, long length)
static ImageRec * ImageOpen(const char *fileName)
static bool writeGraphToVRMLFile(SoNode *root, const QString &filename)
static bool deserialiseSoMaterial(QByteArray &, SoMaterial *&)
static void ensureInitLineWidthAndPointSize(SoQtRenderArea *)
static QByteArray serialiseSoMaterial(SoMaterial *)
static double getValueLineWidthSlider(const QSlider *)
static QList< SoGLRenderAction::TransparencyType > getAllTransparencyTypes()
static QByteArray serialize(const SbRotation &)
static void setLimitsLineWidthSlider(QSlider *)
static void setMatColor(SoMaterial *, const double &r, const double &g, const double &b, const double &brightness=0.0, const double &transp=0.0)
static QImage imageFromRGBFile(const QString &filename)
static QPixmap renderToPixmap(VP1ExaminerViewer *ra, int pixels_x, int pixels_y, bool transparent_background=false, double actualRenderedSizeFact=1.0)
static SoGLRenderAction::TransparencyType intToTransparencyType(int)
static void getLineWidthRanges(double &min, double &max, double &granularity)
static double getValuePointSizeSlider(const QSlider *)
static QColor sbcol2qcol(const SbColor &)
static void setValuePointSizeSlider(QSlider *, const double &value)
static QByteArray serializeSoCameraParameters(const SoCamera &)
static bool writeGraphToFile(SoNode *root, const QString &filename)
static SoNode * createCircle(const double &radius)
static bool deserialize(QByteArray &, SbRotation &)
static SbColor qcol2sbcol(const QColor &)
static bool changePathTail(SoPath *path, SoNode *commonBranchPoint, SoNode *newtail)
static QString transparencyType2PrettyString(SoGLRenderAction::TransparencyType)
static void setLimitsPointSizeSlider(QSlider *)
static SoNode * createEllipse(const double &radiusX, const double &radiusY, const int &numnodes=12)
static bool deserializeSoCameraParameters(QByteArray &, SoCamera &)
static void getPointSizeRanges(double &min, double &max, double &granularity)
static void setValueLineWidthSlider(QSlider *, const double &value)
static QImage renderToImage(VP1ExaminerViewer *ra, int pixels_x, int pixels_y, bool transparent_background=false, double actualRenderedSizeFact=1.0)
static SoSeparator * readGraphFromFile(const QString &filename)
static int transparencyTypeToInt(SoGLRenderAction::TransparencyType)
static SoGLRenderAction::TransparencyType getDefaultVP1TransparencyType()
static QPixmap pixmapFromRGBFile(const QString &filename)
static QString str(const QString &s)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string