20#include "Inventor/nodes/SoMaterial.h"
21#include <Inventor/nodes/SoPerspectiveCamera.h>
22#include <Inventor/nodes/SoOrthographicCamera.h>
23#include <Inventor/nodes/SoGroup.h>
24#include <Inventor/nodes/SoNurbsCurve.h>
25#include <Inventor/nodes/SoCoordinate4.h>
27#include <Inventor/SoPath.h>
28#include <Inventor/SoOffscreenRenderer.h>
29#include "Inventor/Qt/SoQtRenderArea.h"
30#include <Inventor/actions/SoSearchAction.h>
31#include <Inventor/SoDB.h>
32#include <Inventor/actions/SoWriteAction.h>
34#include <Inventor/nodes/SoLineSet.h>
35#include <Inventor/nodes/SoVertexProperty.h>
38#include <Inventor/VRMLnodes/SoVRMLGroup.h>
39#include <Inventor/actions/SoToVRML2Action.h>
47#include <QtCoreVersion>
53 ucharAddress(
auto * pv){
54 return reinterpret_cast<unsigned char *
>(
pv);
64 static void bwtorgba(
unsigned char *b,
unsigned char *l,
int n)
75 static void latorgba(
unsigned char *b,
unsigned char *
a,
unsigned char *l,
int n)
87 unsigned char *b,
unsigned char *l,
int n)
94 l += 4; ++
r; ++g; ++b;
99 unsigned char *b,
unsigned char *
a,
unsigned char *l,
int n)
106 l += 4; ++
r; ++g; ++b; ++
a;
129 *array = std::byteswap (*array);
138 const bool swapFlag = std::endian::native == std::endian::little;
141 fprintf(stderr,
"Out of memory!\n");
144 if (!(image->file = fopen(fileName,
"rb"))) {
150 int bytesRead = fread(image, 1, 12, image->file);
152 if (bytesRead != 12) {
153 fprintf(stderr,
"fread failed!\n");
164 image->imagic = std::byteswap (image->imagic);
165 image->type = std::byteswap (image->type);
166 image->dim = std::byteswap (image->dim);
167 image->xsize = std::byteswap (image->xsize);
168 image->ysize = std::byteswap (image->ysize);
169 image->zsize = std::byteswap (image->zsize);
173 const unsigned int colourBuffSize=image->xsize*256u;
174 image->tmp = ucharAddress(malloc(colourBuffSize));
175 image->tmpR = ucharAddress(malloc(colourBuffSize));
176 image->tmpG = ucharAddress(malloc(colourBuffSize));
177 image->tmpB = ucharAddress(malloc(colourBuffSize));
178 if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
179 image->tmpB == NULL) {
180 fprintf(stderr,
"Out of memory!\n");
185 if ((image->type & 0xFF00) == 0x0100) {
186 size_t x = ((size_t)image->ysize * (size_t)image->zsize) *
sizeof(
unsigned);
189 image->rowStart = (
unsigned *)malloc(
x);
190 image->rowSize = (
int *)malloc(
x);
191 if (image->rowStart == NULL || image->rowSize == NULL) {
192 fprintf(stderr,
"Out of memory!\n");
195 image->rleEnd = 512 + (2 *
x);
196 const int fseekRetVal= fseek(image->file, 512, SEEK_SET);
197 if (fseekRetVal !=0){
198 fprintf(stderr,
"Something very wrong with fseek near line 205 of VP1QtInventorUtils.cxx");
200 size_t bytesRead = 0;
201 bytesRead = fread(image->rowStart, 1,
x, image->file);
203 bytesRead = fread(image->rowSize, 1,
x, image->file);
208 ConvertLong((
unsigned *)image->rowSize,
x/(
int)
sizeof(
int));
211 image->rowStart = NULL;
212 image->rowSize = NULL;
224 free(image->rowSize);
225 free(image->rowStart);
230 unsigned char *buf,
int y,
int z)
232 unsigned char *iPtr, *oPtr,
pixel;
236 if ((image->type & 0xFF00) == 0x0100) {
238 int okseek = fseek(image->file, (
long)image->rowStart[
y+
z*image->ysize], SEEK_SET);
239 int okread = fread(image->tmp, 1, (
unsigned int)image->rowSize[
y+
z*image->ysize],
264 const unsigned int yDim(
y*image->xsize), zDim(
z*image->xsize*image->ysize);
265 int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
268 size_t bytesRead = 0;
269 bytesRead = fread(buf, 1, image->xsize, image->file);
275 std::cout <<
"Warning! ImageGetRow() - no 'image'..." << std::endl;
281 unsigned *
base, *lptr;
282 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
291 (*width)=image->xsize;
292 (*height)=image->ysize;
293 (*components)=image->zsize;
294 const unsigned int imageWidth = image->xsize;
295 const unsigned int imageHeight = image->ysize;
296 const unsigned int uintSize(
sizeof(
unsigned)), ucharSize(
sizeof(
unsigned char));
297 const unsigned int colourBufSize=imageWidth*ucharSize;
298 base =
reinterpret_cast<unsigned *
>(malloc(imageWidth*imageHeight*uintSize));
299 rbuf = ucharAddress(malloc(colourBufSize));
300 gbuf = ucharAddress(malloc(colourBufSize));
301 bbuf = ucharAddress(malloc(colourBufSize));
302 abuf = ucharAddress(malloc(colourBufSize));
303 if(!
base || !rbuf || !gbuf || !bbuf) {
306 if (rbuf) free(rbuf);
307 if (gbuf) free(gbuf);
308 if (bbuf) free(bbuf);
309 if (abuf) free(abuf);
313 for (
y=0;
y<image->ysize; ++
y) {
314 if (image->zsize>=4) {
321 rgbatorgba(rbuf,gbuf,bbuf,abuf,ucharAddress(lptr),image->xsize);
322 lptr += image->xsize;
323 }
else if(image->zsize==3) {
327 rgbtorgba(rbuf,gbuf,bbuf,ucharAddress(lptr),image->xsize);
328 lptr += image->xsize;
329 }
else if(image->zsize==2) {
332 latorgba(rbuf,abuf,ucharAddress(lptr),image->xsize);
333 lptr += image->xsize;
336 bwtorgba(rbuf,ucharAddress(lptr),image->xsize);
337 lptr += image->xsize;
346 return (
unsigned *)
base;
401 constexpr int maxheight(10'000);
402 constexpr int maxwidth(10'000);
403 auto inbounds = [](
int w,
int h)->
bool{
404 return (w>0 and w<maxwidth) and (
h>0 and
h<maxheight);
407 if( not inbounds(
width, height)){
408 std::cout <<
"VP1QtInventorUtils::imageFromRGBFile - read_texture failed?" << std::endl;
410 height = std::clamp(height, 0, maxheight);
412 unsigned char * data =
reinterpret_cast<unsigned char*
>(imagedata);
414 QImage im(
width,height, ( components <= 3 ? QImage::Format_RGB32 : QImage::Format_ARGB32 ) );
417 for (;
y<height; ++
y) {
420 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() );
432 bool transparent_background,
double actualRenderedSizeFact )
445 if (actualRenderedSizeFact!=1.0&&!transparent_background) {
447 static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
448 static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
451 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
454 if (transparent_background) {
459 SbColor save_bgd = ra->getBackgroundColor();
460 SbBool save_redraw = ra->isAutoRedraw();
462 ra->setAutoRedraw(
false);
465 QImage im_black_bgd, im_white_bgd;
466 if (actualRenderedSizeFact==1.0) {
467 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
468 im_black_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
469 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
470 im_white_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
472 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
473 im_black_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
474 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
475 im_white_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
478 ra->setBackgroundColor(save_bgd);
479 ra->setAutoRedraw(save_redraw);
481 if (actualRenderedSizeFact==1.0)
485 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
502 SoNode *rootOverlay = ra->getOverlaySceneGraph();
507 SbViewportRegion myViewport;
508 myViewport.setWindowSize(SbVec2s(pixels_x,pixels_y));
510 QString tmppath(QDir::tempPath());
511 if (!tmppath.endsWith(QDir::separator()))
512 tmppath+=QDir::separator();
513 tmppath +=
"vp1tmpfileXXXXXX.rgb";
514 std::string stmppath = tmppath.toStdString();
515 int tmpfd = mkstemps (stmppath.data(), 4);
516 FILE* tmpf = fdopen (tmpfd,
"w");
517 QString tmpfile (stmppath.c_str());
520 SoOffscreenRenderer *myRenderer =
new SoOffscreenRenderer(myViewport);
523 myRenderer->setBackgroundColor(ra->getBackgroundColor());
526 myRenderer->setComponents(SoOffscreenRenderer::RGB_TRANSPARENCY);
527 myRenderer->getGLRenderAction()->setTransparencyType(ra->getTransparencyType());
531 SbBool smoothing;
int numPasses;
532 ra->getAntialiasing (smoothing, numPasses);
533 myRenderer->getGLRenderAction()->setSmoothing (smoothing);
534 myRenderer->getGLRenderAction()->setNumPasses(numPasses);
541 if (!myRenderer->render(root)) {
551 bool okOver = myRenderer->render(rootOverlay);
564 if (!myRenderer->writeToRGB(tmpf)) {
566 if (QFile::exists(tmpfile))
567 QFile(tmpfile).remove();
581 if (QFile::exists(tmpfile))
582 QFile(tmpfile).remove();
591 bool transparent_background,
double actualRenderedSizeFact )
593 return QPixmap::fromImage(
renderToImage(ra, pixels_x, pixels_y, transparent_background, actualRenderedSizeFact));
599 if (im_black_bgd.isNull()||im_white_bgd.isNull()||im_black_bgd.size()!=im_white_bgd.size())
602 QImage im(im_black_bgd.size(),QImage::Format_ARGB32);
604 int width = im.width();
605 int height = im.height();
606 QRgb white = qRgba(255,255,255,255);
607 QRgb black = qRgba(0,0,0,255);
610 for (
int y = 0;
y < height; ++
y) {
611 if (im_black_bgd.pixel(
x,
y)==im_white_bgd.pixel(
x,
y)) {
612 im.setPixel(
x,
y,im_white_bgd.pixel(
x,
y));
613 }
else if (im_black_bgd.pixel(
x,
y)==black&&im_white_bgd.pixel(
x,
y)==white) {
614 im.setPixel(
x,
y,Qt::transparent);
617 QColor pix_b = QColor(im_black_bgd.pixel(
x,
y));
618 QColor pix_w = QColor(im_white_bgd.pixel(
x,
y));
619 qreal alpha = 1.0 - pix_w.redF() + pix_b.redF();
621 im.setPixel(
x,
y,Qt::transparent);
623 im.setPixel(
x,
y,qRgba(
static_cast<int>(pix_b.redF()/alpha*255+0.5),
624 static_cast<int>(pix_b.greenF()/alpha*255+0.5),
625 static_cast<int>(pix_b.blueF()/alpha*255+0.5),
626 static_cast<int>(alpha*255+0.5)));
638 return SoGLRenderAction::DELAYED_BLEND;
644 QList<SoGLRenderAction::TransparencyType> l;
645 l << SoGLRenderAction::NONE
646 << SoGLRenderAction::SCREEN_DOOR
647 << SoGLRenderAction::ADD
648 << SoGLRenderAction::DELAYED_ADD
649 << SoGLRenderAction::SORTED_OBJECT_ADD
650 << SoGLRenderAction::BLEND
651 << SoGLRenderAction::DELAYED_BLEND
652 << SoGLRenderAction::SORTED_OBJECT_BLEND
653 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD
654 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND
655 << SoGLRenderAction::SORTED_LAYERS_BLEND;
663 case SoGLRenderAction::SCREEN_DOOR:
return 0;
664 case SoGLRenderAction::ADD:
return 1;
665 case SoGLRenderAction::DELAYED_ADD:
return 2;
666 case SoGLRenderAction::SORTED_OBJECT_ADD:
return 3;
667 case SoGLRenderAction::BLEND:
return 4;
668 case SoGLRenderAction::DELAYED_BLEND:
return 5;
669 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return 6;
670 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return 7;
671 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return 8;
672 case SoGLRenderAction::NONE:
return 9;
673 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return 10;
675 VP1Msg::messageDebug(
"VP1QtInventorUtils::transparencyTypeToInt ERROR: Unknown transparency type");
683 case 0:
return SoGLRenderAction::SCREEN_DOOR;
684 case 1:
return SoGLRenderAction::ADD;
685 case 2:
return SoGLRenderAction::DELAYED_ADD;
686 case 3:
return SoGLRenderAction::SORTED_OBJECT_ADD;
687 case 4:
return SoGLRenderAction::BLEND;
688 case 5:
return SoGLRenderAction::DELAYED_BLEND;
689 case 6:
return SoGLRenderAction::SORTED_OBJECT_BLEND;
690 case 7:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD;
691 case 8:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND;
692 case 9:
return SoGLRenderAction::NONE;
693 case 10:
return SoGLRenderAction::SORTED_LAYERS_BLEND;
696 return SoGLRenderAction::DELAYED_BLEND;
705 case SoGLRenderAction::DELAYED_BLEND:
return "Delayed blend";
break;
706 case SoGLRenderAction::SCREEN_DOOR:
return "Screen door";
break;
707 case SoGLRenderAction::ADD:
return "Add";
break;
708 case SoGLRenderAction::DELAYED_ADD:
return "Delayed add";
break;
709 case SoGLRenderAction::SORTED_OBJECT_ADD:
return "Sorted object add";
break;
710 case SoGLRenderAction::BLEND:
return "Blend (Best for Geo volumes)";
break;
711 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return "Sorted object blend (Best for physics objects: jets, tracks, ...)";
break;
712 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return "Sorted object sorted triangle add";
break;
713 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return "Sorted object sorted triangle blend";
break;
714 case SoGLRenderAction::NONE:
return "None";
break;
715 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return "Sorted layers blend";
break;
726 QByteArray byteArray;
727 QBuffer buffer(&byteArray);
728 buffer.open(QIODevice::WriteOnly);
729 QDataStream out(&buffer);
734 rot.getValue (q0,q1,q2,q3);
744 +QString::number(q0)+
", "+QString::number(q1)+
", "
745 +QString::number(q2)+
", "+QString::number(q3)+
")");
758 buffer.open(QIODevice::ReadOnly);
759 QDataStream state(&buffer);
763 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
771 rot.setValue (q0,q1,q2,q3);
776 +QString::number(q0)+
", "+QString::number(q1)+
", "
777 +QString::number(q2)+
", "+QString::number(q3)+
")");
789 rot.setValue (q0,q1,q2,q3);
794 +QString::number(q0)+
", "+QString::number(q1)+
", "
795 +QString::number(q2)+
", "+QString::number(q3)+
")");
809 QByteArray byteArray;
810 QBuffer buffer(&byteArray);
811 buffer.open(QIODevice::WriteOnly);
812 QDataStream out(&buffer);
824 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
837 buffer.open(QIODevice::ReadOnly);
838 QDataStream state(&buffer);
842 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
854 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
869 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
886 QByteArray byteArray;
887 QBuffer buffer(&byteArray);
888 buffer.open(QIODevice::WriteOnly);
889 QDataStream out(&buffer);
893 SbRotation camrot = cam.orientation.getValue();
895 SbVec3f campos = cam.position.getValue();
897 float f_aspectRatio(cam.aspectRatio.getValue());
898 float f_nearDistance(cam.nearDistance.getValue());
899 float f_farDistance(cam.farDistance.getValue());
900 float f_focalDistance(cam.focalDistance.getValue());
901 out << (double)f_aspectRatio;
902 out << (double)f_nearDistance;
903 out << (double)f_farDistance;
904 out << (double)f_focalDistance;
907 switch (cam.viewportMapping.getValue()) {
908 case SoCamera::CROP_VIEWPORT_FILL_FRAME: viewportmap = 0;
break;
909 case SoCamera::CROP_VIEWPORT_LINE_FRAME: viewportmap = 1;
break;
910 case SoCamera::CROP_VIEWPORT_NO_FRAME: viewportmap = 2;
break;
911 case SoCamera::ADJUST_CAMERA: viewportmap = 3;
break;
912 case SoCamera::LEAVE_ALONE: viewportmap = 4;
break;
918 if (cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId()))
920 else if (cam.getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId()))
925 out << (double)static_cast<const SoPerspectiveCamera*>(&cam)->heightAngle.getValue();
926 }
else if (camtype==1) {
927 out << (double)static_cast<const SoOrthographicCamera*>(&cam)->height.getValue();
936 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
937 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
938 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
939 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
940 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
942 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
945 +QString::number(
static_cast<const SoPerspectiveCamera*
>(&cam)->heightAngle.getValue()));
948 +QString::number(
static_cast<const SoOrthographicCamera*
>(&cam)->height.getValue()));
959 if (ba==QByteArray())
964 buffer.open(QIODevice::ReadOnly);
965 QDataStream state(&buffer);
969 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
972 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
975 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
978 bool save = cam.enableNotify(
false);
980 cam.orientation.setValue(rot);
981 cam.position.setValue(pos);
983 float f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
985 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
986 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
987 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
988 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
992 switch (viewportmap) {
993 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
994 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
995 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
996 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
997 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1001 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1006 float f_orthopersp_heightpar(-999);
1009 if (!passedcameraisperspective)
1011 state >> f_orthopersp_heightpar;
1012 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1013 }
else if (camtype==1) {
1015 if (passedcameraisperspective)
1017 state >> f_orthopersp_heightpar;
1018 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1022 cam.enableNotify(
true);
1030 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1031 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1032 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1033 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1034 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1036 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1039 +QString::number(f_orthopersp_heightpar));
1042 +QString::number(f_orthopersp_heightpar));
1050 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
1053 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
1056 bool save = cam.enableNotify(
false);
1058 cam.orientation.setValue(rot);
1059 cam.position.setValue(pos);
1061 double f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
1063 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
1064 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
1065 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
1066 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
1070 switch (viewportmap) {
1071 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
1072 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
1073 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
1074 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
1075 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1079 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1084 double f_orthopersp_heightpar(-999);
1087 if (!passedcameraisperspective)
1089 state >> f_orthopersp_heightpar;
1090 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1091 }
else if (camtype==1) {
1093 if (passedcameraisperspective)
1095 state >> f_orthopersp_heightpar;
1096 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1100 cam.enableNotify(
true);
1108 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1109 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1110 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1111 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1112 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1114 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1117 +QString::number(f_orthopersp_heightpar));
1120 +QString::number(f_orthopersp_heightpar));
1125 cam.unrefNoDelete();
1133 return SbColor( col.red()/255.0, col.green()/255.0, col.blue()/255.0 );
1140 col.getValue(
r,g,b);
1141 return QColor::fromRgbF(
r,g,b );
1147 if (!m||m->ambientColor.getNum()!=1
1148 ||m->diffuseColor.getNum()!=1
1149 ||m->specularColor.getNum()!=1
1150 ||m->emissiveColor.getNum()!=1
1151 ||m->transparency.getNum()!=1
1152 ||m->shininess.getNum()!=1) {
1154 "Passed material must have exactly one value in each of the 6 fields!!");
1155 return QByteArray();
1160 QByteArray byteArray;
1161 QBuffer buffer(&byteArray);
1162 buffer.open(QIODevice::WriteOnly);
1163 QDataStream out(&buffer);
1166 out << QString(
"somat_v1_begin");
1171 out << (double)m->shininess[0];
1172 out << (double)m->transparency[0];
1173 out << QString(
"somat_end");
1185 if (!m||m->ambientColor.getNum()!=1
1186 ||m->diffuseColor.getNum()!=1
1187 ||m->specularColor.getNum()!=1
1188 ||m->emissiveColor.getNum()!=1
1189 ||m->transparency.getNum()!=1
1190 ||m->shininess.getNum()!=1) {
1192 "Passed material must have exactly one value in each of the 6 fields!!");
1197 QBuffer buffer(&ba);
1198 buffer.open(QIODevice::ReadOnly);
1199 QDataStream stream(&buffer);
1201 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
1204 QString
str; stream >>
str;
1205 if (
str!=
"somat_v1_begin")
1208 QColor ambientcol; stream >> ambientcol;
1209 if (!ambientcol.isValid())
1212 QColor diffusecol; stream >> diffusecol;
1213 if (!diffusecol.isValid())
1216 QColor specularcol; stream >> specularcol;
1217 if (!specularcol.isValid())
1220 QColor emissivecol; stream >> emissivecol;
1221 if (!emissivecol.isValid())
1224 if(ba.size()==106) {
1226 float shininess; stream >> shininess;
1227 if (shininess<0.0f||shininess>1.0f)
1230 float transparency; stream >> transparency;
1231 if (transparency<0.0f||transparency>1.0f)
1235 if (
str!=
"somat_end")
1241 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1242 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1243 m->specularColor.setValue(
qcol2sbcol(specularcol));
1244 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1245 m->shininess.setValue(shininess);
1246 m->transparency.setValue(transparency);
1250 double shininess; stream >> shininess;
1251 if (shininess<0.0||shininess>1.0)
1254 double transparency; stream >> transparency;
1255 if (transparency<0.0||transparency>1.0)
1259 if (
str!=
"somat_end")
1265 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1266 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1267 m->specularColor.setValue(
qcol2sbcol(specularcol));
1268 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1269 m->shininess.setValue(shininess);
1270 m->transparency.setValue(transparency);
1279 SoGroup* grp =
new SoGroup;
1282 SoCoordinate4 *
coord =
new SoCoordinate4;
1283 const double invsqrttwo=0.707106781186547;
1286 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1287 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1288 coord->point.set1Value(icoord++,SbVec4f(0,1*radius,0,1));
1289 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1290 coord->point.set1Value(icoord++,SbVec4f(-1*radius,0,0,1));
1291 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1292 coord->point.set1Value(icoord++,SbVec4f(0,-1*radius,0,1));
1293 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1294 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1296 SoNurbsCurve * curve =
new SoNurbsCurve;
1297 curve->numControlPoints = icoord;
1301 curve->knotVector.set1Value(iknot++,0);
1302 curve->knotVector.set1Value(iknot++,0);
1303 curve->knotVector.set1Value(iknot++,0);
1304 curve->knotVector.set1Value(iknot++,1);
1305 curve->knotVector.set1Value(iknot++,1);
1306 curve->knotVector.set1Value(iknot++,2);
1307 curve->knotVector.set1Value(iknot++,2);
1308 curve->knotVector.set1Value(iknot++,3);
1309 curve->knotVector.set1Value(iknot++,3);
1310 curve->knotVector.set1Value(iknot++,4);
1311 curve->knotVector.set1Value(iknot++,4);
1312 curve->knotVector.set1Value(iknot++,4);
1313 grp->addChild(
coord);
1314 grp->addChild(curve);
1316 grp->unrefNoDelete();
1323 SoVertexProperty *vertices =
new SoVertexProperty();
1326 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1327 for (
int i = 1; i < numnodes; i++)
1329 vertices->vertex.set1Value(iver++,
1330 cos(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusX,
1331 sin(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusY,0.0);
1333 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1335 SoLineSet * ellipse =
new SoLineSet();
1336 ellipse->numVertices = iver;
1337 ellipse->vertexProperty = vertices;
1345 if (!path||!commonBranchPoint||!newtail)
1349 sa.setInterest(SoSearchAction::FIRST);
1350 sa.setNode(newtail);
1351 sa.apply(commonBranchPoint);
1354 SoPath * newpath = sa.getPath();
1358 for (
int i=0;i<path->getLength();++i) {
1359 if (path->getNode(i)==commonBranchPoint) {
1361 path->truncate(i+1);
1366 path->append(newpath);
1387 buffer = (
char *)malloc(1024);
1391 SoWriteAction wa(&out);
1402 SoToVRML2Action vwa;
1405 SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
1408 out.openFile(qPrintable(filename));
1409 out.setHeaderString(
"#VRML V2.0 utf8");
1410 SoWriteAction wra(&out);
1425 root->unrefNoDelete();
1427 QFile data(filename);
1428 if (data.open(QFile::WriteOnly | QFile::Truncate)) {
1429 QTextStream out(&data);
1430#if QTCORE_VERSION >= 0x050E00
1431 out << s << Qt::endl;
1446 if (!in.openFile(filename.toStdString().c_str()))
1448 return SoDB::readAll(&in);
1460 root->unrefNoDelete();
1478 const double& brightness,
const double& transp )
1486 const double& brightness,
const double& transp )
1488 setMatColor( m, col.redF(), col.greenF(), col.blueF(), brightness, transp);
1521 "purpose of getting supported line widths and point sizes!");
1525 SbVec2f range;
float granularity;
1526 ra->getLineWidthLimits(range, granularity);
1528 range.getValue(
a,b);
1532 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined line widths supported by hardware (min,max,granularity) = ("
1534 ra->getPointSizeLimits(range, granularity);
1535 range.getValue(
a,b);
1539 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined point sizes supported by hardware (min,max,granularity) = ("
1566 slider->setRange(0,nsteps);
1567 slider->setSingleStep(1);
1568 slider->setPageStep(stepsPerUnit);
1578 int nsteps = std::min(1000,std::max<int>(0,
1580 int stepsPerUnit = std::min(nsteps,std::max<int>(1,
1582 slider->setRange(0,nsteps);
1583 slider->setSingleStep(1);
1584 slider->setPageStep(stepsPerUnit);
1594 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1596 if (slider->value()!=itarget)
1597 slider->setValue(itarget);
1607 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1609 if (slider->value()!=itarget)
1610 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