21#include "Inventor/nodes/SoMaterial.h"
22#include <Inventor/nodes/SoPerspectiveCamera.h>
23#include <Inventor/nodes/SoOrthographicCamera.h>
24#include <Inventor/nodes/SoGroup.h>
25#include <Inventor/nodes/SoNurbsCurve.h>
26#include <Inventor/nodes/SoCoordinate4.h>
28#include <Inventor/SoPath.h>
29#include <Inventor/SoOffscreenRenderer.h>
30#include "Inventor/Qt/SoQtRenderArea.h"
31#include <Inventor/actions/SoSearchAction.h>
32#include <Inventor/SoDB.h>
33#include <Inventor/actions/SoWriteAction.h>
35#include <Inventor/nodes/SoLineSet.h>
36#include <Inventor/nodes/SoVertexProperty.h>
39#include <Inventor/VRMLnodes/SoVRMLGroup.h>
40#include <Inventor/actions/SoToVRML2Action.h>
49#include <QtCoreVersion>
54 ucharAddress(
auto * pv){
55 return reinterpret_cast<unsigned char *
>(
pv);
65 static void bwtorgba(
unsigned char *b,
unsigned char *l,
int n)
76 static void latorgba(
unsigned char *b,
unsigned char *
a,
unsigned char *l,
int n)
88 unsigned char *b,
unsigned char *l,
int n)
95 l += 4; ++
r; ++g; ++b;
100 unsigned char *b,
unsigned char *
a,
unsigned char *l,
int n)
107 l += 4; ++
r; ++g; ++b; ++
a;
144 endianTest.testWord = 1;
145 if (endianTest.testByte[0] == 1) {
153 fprintf(stderr,
"Out of memory!\n");
156 if ((image->file = fopen(fileName,
"rb")) == NULL) {
161 int bytesRead = fread(image, 1, 12, image->file);
164 fprintf(stderr,
"fread failed!\n");
181 const unsigned int colourBuffSize=image->xsize*256u;
182 image->tmp = ucharAddress(malloc(colourBuffSize));
183 image->tmpR = ucharAddress(malloc(colourBuffSize));
184 image->tmpG = ucharAddress(malloc(colourBuffSize));
185 image->tmpB = ucharAddress(malloc(colourBuffSize));
186 if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
187 image->tmpB == NULL) {
188 fprintf(stderr,
"Out of memory!\n");
193 if ((image->type & 0xFF00) == 0x0100) {
194 size_t x = ((size_t)image->ysize * (size_t)image->zsize) *
sizeof(
unsigned);
197 image->rowStart = (
unsigned *)malloc(
x);
198 image->rowSize = (
int *)malloc(
x);
199 if (image->rowStart == NULL || image->rowSize == NULL) {
200 fprintf(stderr,
"Out of memory!\n");
203 image->rleEnd = 512 + (2 *
x);
204 const int fseekRetVal= fseek(image->file, 512, SEEK_SET);
205 if (fseekRetVal !=0){
206 fprintf(stderr,
"Something very wrong with fseek near line 205 of VP1QtInventorUtils.cxx");
208 size_t bytesRead = 0;
209 bytesRead = fread(image->rowStart, 1,
x, image->file);
211 bytesRead = fread(image->rowSize, 1,
x, image->file);
216 ConvertLong((
unsigned *)image->rowSize,
x/(
int)
sizeof(
int));
219 image->rowStart = NULL;
220 image->rowSize = NULL;
232 free(image->rowSize);
233 free(image->rowStart);
238 unsigned char *buf,
int y,
int z)
240 unsigned char *iPtr, *oPtr,
pixel;
244 if ((image->type & 0xFF00) == 0x0100) {
246 int okseek = fseek(image->file, (
long)image->rowStart[
y+
z*image->ysize], SEEK_SET);
247 int okread = fread(image->tmp, 1, (
unsigned int)image->rowSize[
y+
z*image->ysize],
272 const unsigned int yDim(
y*image->xsize), zDim(
z*image->xsize*image->ysize);
273 int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
276 size_t bytesRead = 0;
277 bytesRead = fread(buf, 1, image->xsize, image->file);
283 std::cout <<
"Warning! ImageGetRow() - no 'image'..." << std::endl;
289 unsigned *
base, *lptr;
290 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
299 (*width)=image->xsize;
300 (*height)=image->ysize;
301 (*components)=image->zsize;
302 const unsigned int imageWidth = image->xsize;
303 const unsigned int imageHeight = image->ysize;
304 const unsigned int uintSize(
sizeof(
unsigned)), ucharSize(
sizeof(
unsigned char));
305 const unsigned int colourBufSize=imageWidth*ucharSize;
306 base =
reinterpret_cast<unsigned *
>(malloc(imageWidth*imageHeight*uintSize));
307 rbuf = ucharAddress(malloc(colourBufSize));
308 gbuf = ucharAddress(malloc(colourBufSize));
309 bbuf = ucharAddress(malloc(colourBufSize));
310 abuf = ucharAddress(malloc(colourBufSize));
311 if(!
base || !rbuf || !gbuf || !bbuf) {
314 if (rbuf) free(rbuf);
315 if (gbuf) free(gbuf);
316 if (bbuf) free(bbuf);
317 if (abuf) free(abuf);
321 for (
y=0;
y<image->ysize; ++
y) {
322 if (image->zsize>=4) {
329 rgbatorgba(rbuf,gbuf,bbuf,abuf,ucharAddress(lptr),image->xsize);
330 lptr += image->xsize;
331 }
else if(image->zsize==3) {
335 rgbtorgba(rbuf,gbuf,bbuf,ucharAddress(lptr),image->xsize);
336 lptr += image->xsize;
337 }
else if(image->zsize==2) {
340 latorgba(rbuf,abuf,ucharAddress(lptr),image->xsize);
341 lptr += image->xsize;
344 bwtorgba(rbuf,ucharAddress(lptr),image->xsize);
345 lptr += image->xsize;
354 return (
unsigned *)
base;
409 constexpr int maxheight(10'000);
410 constexpr int maxwidth(10'000);
411 auto inbounds = [](
int w,
int h)->
bool{
412 return (w>0 and w<maxwidth) and (
h>0 and
h<maxheight);
415 if( not inbounds(
width, height)){
416 std::cout <<
"VP1QtInventorUtils::imageFromRGBFile - read_texture failed?" << std::endl;
418 height = std::clamp(height, 0, maxheight);
420 unsigned char *
data =
reinterpret_cast<unsigned char*
>(imagedata);
422 QImage im(
width,height, ( components <= 3 ? QImage::Format_RGB32 : QImage::Format_ARGB32 ) );
425 for (;
y<height; ++
y) {
440 bool transparent_background,
double actualRenderedSizeFact )
453 if (actualRenderedSizeFact!=1.0&&!transparent_background) {
455 static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
456 static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
459 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
462 if (transparent_background) {
467 SbColor save_bgd = ra->getBackgroundColor();
468 SbBool save_redraw = ra->isAutoRedraw();
470 ra->setAutoRedraw(
false);
473 QImage im_black_bgd, im_white_bgd;
474 if (actualRenderedSizeFact==1.0) {
475 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
476 im_black_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
477 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
478 im_white_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
480 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
481 im_black_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
482 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
483 im_white_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
486 ra->setBackgroundColor(save_bgd);
487 ra->setAutoRedraw(save_redraw);
489 if (actualRenderedSizeFact==1.0)
493 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
510 SoNode *rootOverlay = ra->getOverlaySceneGraph();
515 SbViewportRegion myViewport;
516 myViewport.setWindowSize(SbVec2s(pixels_x,pixels_y));
518 QString tmppath(QDir::tempPath());
519 if (!tmppath.endsWith(QDir::separator()))
520 tmppath+=QDir::separator();
521 tmppath +=
"vp1tmpfileXXXXXX.rgb";
522 std::string stmppath = tmppath.toStdString();
523 int tmpfd = mkstemps (stmppath.data(), 4);
524 FILE* tmpf = fdopen (tmpfd,
"w");
525 QString tmpfile (stmppath.c_str());
528 SoOffscreenRenderer *myRenderer =
new SoOffscreenRenderer(myViewport);
531 myRenderer->setBackgroundColor(ra->getBackgroundColor());
534 myRenderer->setComponents(SoOffscreenRenderer::RGB_TRANSPARENCY);
535 myRenderer->getGLRenderAction()->setTransparencyType(ra->getTransparencyType());
539 SbBool smoothing;
int numPasses;
540 ra->getAntialiasing (smoothing, numPasses);
541 myRenderer->getGLRenderAction()->setSmoothing (smoothing);
542 myRenderer->getGLRenderAction()->setNumPasses(numPasses);
549 if (!myRenderer->render(root)) {
559 bool okOver = myRenderer->render(rootOverlay);
572 if (!myRenderer->writeToRGB(tmpf)) {
574 if (QFile::exists(tmpfile))
575 QFile(tmpfile).remove();
589 if (QFile::exists(tmpfile))
590 QFile(tmpfile).remove();
599 bool transparent_background,
double actualRenderedSizeFact )
601 return QPixmap::fromImage(
renderToImage(ra, pixels_x, pixels_y, transparent_background, actualRenderedSizeFact));
607 if (im_black_bgd.isNull()||im_white_bgd.isNull()||im_black_bgd.size()!=im_white_bgd.size())
610 QImage im(im_black_bgd.size(),QImage::Format_ARGB32);
612 int width = im.width();
613 int height = im.height();
614 QRgb white = qRgba(255,255,255,255);
615 QRgb black = qRgba(0,0,0,255);
618 for (
int y = 0;
y < height; ++
y) {
619 if (im_black_bgd.pixel(
x,
y)==im_white_bgd.pixel(
x,
y)) {
620 im.setPixel(
x,
y,im_white_bgd.pixel(
x,
y));
621 }
else if (im_black_bgd.pixel(
x,
y)==black&&im_white_bgd.pixel(
x,
y)==white) {
622 im.setPixel(
x,
y,Qt::transparent);
625 QColor pix_b = QColor(im_black_bgd.pixel(
x,
y));
626 QColor pix_w = QColor(im_white_bgd.pixel(
x,
y));
627 qreal alpha = 1.0 - pix_w.redF() + pix_b.redF();
629 im.setPixel(
x,
y,Qt::transparent);
631 im.setPixel(
x,
y,qRgba(
static_cast<int>(pix_b.redF()/alpha*255+0.5),
632 static_cast<int>(pix_b.greenF()/alpha*255+0.5),
633 static_cast<int>(pix_b.blueF()/alpha*255+0.5),
634 static_cast<int>(alpha*255+0.5)));
646 return SoGLRenderAction::DELAYED_BLEND;
652 QList<SoGLRenderAction::TransparencyType> l;
653 l << SoGLRenderAction::NONE
654 << SoGLRenderAction::SCREEN_DOOR
655 << SoGLRenderAction::ADD
656 << SoGLRenderAction::DELAYED_ADD
657 << SoGLRenderAction::SORTED_OBJECT_ADD
658 << SoGLRenderAction::BLEND
659 << SoGLRenderAction::DELAYED_BLEND
660 << SoGLRenderAction::SORTED_OBJECT_BLEND
661 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD
662 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND
663 << SoGLRenderAction::SORTED_LAYERS_BLEND;
671 case SoGLRenderAction::SCREEN_DOOR:
return 0;
672 case SoGLRenderAction::ADD:
return 1;
673 case SoGLRenderAction::DELAYED_ADD:
return 2;
674 case SoGLRenderAction::SORTED_OBJECT_ADD:
return 3;
675 case SoGLRenderAction::BLEND:
return 4;
676 case SoGLRenderAction::DELAYED_BLEND:
return 5;
677 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return 6;
678 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return 7;
679 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return 8;
680 case SoGLRenderAction::NONE:
return 9;
681 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return 10;
683 VP1Msg::messageDebug(
"VP1QtInventorUtils::transparencyTypeToInt ERROR: Unknown transparency type");
691 case 0:
return SoGLRenderAction::SCREEN_DOOR;
692 case 1:
return SoGLRenderAction::ADD;
693 case 2:
return SoGLRenderAction::DELAYED_ADD;
694 case 3:
return SoGLRenderAction::SORTED_OBJECT_ADD;
695 case 4:
return SoGLRenderAction::BLEND;
696 case 5:
return SoGLRenderAction::DELAYED_BLEND;
697 case 6:
return SoGLRenderAction::SORTED_OBJECT_BLEND;
698 case 7:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD;
699 case 8:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND;
700 case 9:
return SoGLRenderAction::NONE;
701 case 10:
return SoGLRenderAction::SORTED_LAYERS_BLEND;
704 return SoGLRenderAction::DELAYED_BLEND;
713 case SoGLRenderAction::DELAYED_BLEND:
return "Delayed blend";
break;
714 case SoGLRenderAction::SCREEN_DOOR:
return "Screen door";
break;
715 case SoGLRenderAction::ADD:
return "Add";
break;
716 case SoGLRenderAction::DELAYED_ADD:
return "Delayed add";
break;
717 case SoGLRenderAction::SORTED_OBJECT_ADD:
return "Sorted object add";
break;
718 case SoGLRenderAction::BLEND:
return "Blend (Best for Geo volumes)";
break;
719 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return "Sorted object blend (Best for physics objects: jets, tracks, ...)";
break;
720 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return "Sorted object sorted triangle add";
break;
721 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return "Sorted object sorted triangle blend";
break;
722 case SoGLRenderAction::NONE:
return "None";
break;
723 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return "Sorted layers blend";
break;
734 QByteArray byteArray;
735 QBuffer buffer(&byteArray);
736 buffer.open(QIODevice::WriteOnly);
737 QDataStream out(&buffer);
742 rot.getValue (q0,q1,q2,q3);
752 +QString::number(q0)+
", "+QString::number(q1)+
", "
753 +QString::number(q2)+
", "+QString::number(q3)+
")");
766 buffer.open(QIODevice::ReadOnly);
767 QDataStream state(&buffer);
771 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
779 rot.setValue (q0,q1,q2,q3);
784 +QString::number(q0)+
", "+QString::number(q1)+
", "
785 +QString::number(q2)+
", "+QString::number(q3)+
")");
797 rot.setValue (q0,q1,q2,q3);
802 +QString::number(q0)+
", "+QString::number(q1)+
", "
803 +QString::number(q2)+
", "+QString::number(q3)+
")");
817 QByteArray byteArray;
818 QBuffer buffer(&byteArray);
819 buffer.open(QIODevice::WriteOnly);
820 QDataStream out(&buffer);
832 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
845 buffer.open(QIODevice::ReadOnly);
846 QDataStream state(&buffer);
850 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
862 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
877 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
894 QByteArray byteArray;
895 QBuffer buffer(&byteArray);
896 buffer.open(QIODevice::WriteOnly);
897 QDataStream out(&buffer);
901 SbRotation camrot = cam.orientation.getValue();
903 SbVec3f campos = cam.position.getValue();
905 float f_aspectRatio(cam.aspectRatio.getValue());
906 float f_nearDistance(cam.nearDistance.getValue());
907 float f_farDistance(cam.farDistance.getValue());
908 float f_focalDistance(cam.focalDistance.getValue());
909 out << (double)f_aspectRatio;
910 out << (double)f_nearDistance;
911 out << (double)f_farDistance;
912 out << (double)f_focalDistance;
915 switch (cam.viewportMapping.getValue()) {
916 case SoCamera::CROP_VIEWPORT_FILL_FRAME: viewportmap = 0;
break;
917 case SoCamera::CROP_VIEWPORT_LINE_FRAME: viewportmap = 1;
break;
918 case SoCamera::CROP_VIEWPORT_NO_FRAME: viewportmap = 2;
break;
919 case SoCamera::ADJUST_CAMERA: viewportmap = 3;
break;
920 case SoCamera::LEAVE_ALONE: viewportmap = 4;
break;
926 if (cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId()))
928 else if (cam.getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId()))
933 out << (double)static_cast<const SoPerspectiveCamera*>(&cam)->heightAngle.getValue();
934 }
else if (camtype==1) {
935 out << (double)static_cast<const SoOrthographicCamera*>(&cam)->height.getValue();
944 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
945 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
946 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
947 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
948 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
950 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
953 +QString::number(
static_cast<const SoPerspectiveCamera*
>(&cam)->heightAngle.getValue()));
956 +QString::number(
static_cast<const SoOrthographicCamera*
>(&cam)->height.getValue()));
967 if (ba==QByteArray())
972 buffer.open(QIODevice::ReadOnly);
973 QDataStream state(&buffer);
977 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
980 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
983 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
986 bool save = cam.enableNotify(
false);
988 cam.orientation.setValue(rot);
989 cam.position.setValue(pos);
991 float f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
993 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
994 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
995 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
996 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
1000 switch (viewportmap) {
1001 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
1002 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
1003 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
1004 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
1005 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1009 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1014 float f_orthopersp_heightpar(-999);
1017 if (!passedcameraisperspective)
1019 state >> f_orthopersp_heightpar;
1020 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1021 }
else if (camtype==1) {
1023 if (passedcameraisperspective)
1025 state >> f_orthopersp_heightpar;
1026 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1030 cam.enableNotify(
true);
1038 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1039 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1040 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1041 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1042 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1044 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1047 +QString::number(f_orthopersp_heightpar));
1050 +QString::number(f_orthopersp_heightpar));
1058 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
1061 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
1064 bool save = cam.enableNotify(
false);
1066 cam.orientation.setValue(rot);
1067 cam.position.setValue(pos);
1069 double f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
1071 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
1072 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
1073 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
1074 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
1078 switch (viewportmap) {
1079 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
1080 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
1081 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
1082 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
1083 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1087 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1092 double f_orthopersp_heightpar(-999);
1095 if (!passedcameraisperspective)
1097 state >> f_orthopersp_heightpar;
1098 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1099 }
else if (camtype==1) {
1101 if (passedcameraisperspective)
1103 state >> f_orthopersp_heightpar;
1104 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1108 cam.enableNotify(
true);
1116 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1117 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1118 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1119 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1120 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1122 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1125 +QString::number(f_orthopersp_heightpar));
1128 +QString::number(f_orthopersp_heightpar));
1133 cam.unrefNoDelete();
1141 return SbColor( col.red()/255.0, col.green()/255.0, col.blue()/255.0 );
1148 col.getValue(
r,g,b);
1149 return QColor::fromRgbF(
r,g,b );
1155 if (!m||m->ambientColor.getNum()!=1
1156 ||m->diffuseColor.getNum()!=1
1157 ||m->specularColor.getNum()!=1
1158 ||m->emissiveColor.getNum()!=1
1159 ||m->transparency.getNum()!=1
1160 ||m->shininess.getNum()!=1) {
1162 "Passed material must have exactly one value in each of the 6 fields!!");
1163 return QByteArray();
1168 QByteArray byteArray;
1169 QBuffer buffer(&byteArray);
1170 buffer.open(QIODevice::WriteOnly);
1171 QDataStream out(&buffer);
1174 out << QString(
"somat_v1_begin");
1179 out << (double)m->shininess[0];
1180 out << (double)m->transparency[0];
1181 out << QString(
"somat_end");
1193 if (!m||m->ambientColor.getNum()!=1
1194 ||m->diffuseColor.getNum()!=1
1195 ||m->specularColor.getNum()!=1
1196 ||m->emissiveColor.getNum()!=1
1197 ||m->transparency.getNum()!=1
1198 ||m->shininess.getNum()!=1) {
1200 "Passed material must have exactly one value in each of the 6 fields!!");
1205 QBuffer buffer(&ba);
1206 buffer.open(QIODevice::ReadOnly);
1207 QDataStream stream(&buffer);
1209 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
1212 QString
str; stream >>
str;
1213 if (
str!=
"somat_v1_begin")
1216 QColor ambientcol; stream >> ambientcol;
1217 if (!ambientcol.isValid())
1220 QColor diffusecol; stream >> diffusecol;
1221 if (!diffusecol.isValid())
1224 QColor specularcol; stream >> specularcol;
1225 if (!specularcol.isValid())
1228 QColor emissivecol; stream >> emissivecol;
1229 if (!emissivecol.isValid())
1232 if(ba.size()==106) {
1234 float shininess; stream >> shininess;
1235 if (shininess<0.0f||shininess>1.0f)
1238 float transparency; stream >> transparency;
1239 if (transparency<0.0f||transparency>1.0f)
1243 if (
str!=
"somat_end")
1249 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1250 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1251 m->specularColor.setValue(
qcol2sbcol(specularcol));
1252 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1253 m->shininess.setValue(shininess);
1254 m->transparency.setValue(transparency);
1258 double shininess; stream >> shininess;
1259 if (shininess<0.0||shininess>1.0)
1262 double transparency; stream >> transparency;
1263 if (transparency<0.0||transparency>1.0)
1267 if (
str!=
"somat_end")
1273 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1274 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1275 m->specularColor.setValue(
qcol2sbcol(specularcol));
1276 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1277 m->shininess.setValue(shininess);
1278 m->transparency.setValue(transparency);
1287 SoGroup* grp =
new SoGroup;
1290 SoCoordinate4 *
coord =
new SoCoordinate4;
1291 const double invsqrttwo=0.707106781186547;
1294 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1295 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1296 coord->point.set1Value(icoord++,SbVec4f(0,1*radius,0,1));
1297 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1298 coord->point.set1Value(icoord++,SbVec4f(-1*radius,0,0,1));
1299 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1300 coord->point.set1Value(icoord++,SbVec4f(0,-1*radius,0,1));
1301 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1302 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1304 SoNurbsCurve * curve =
new SoNurbsCurve;
1305 curve->numControlPoints = icoord;
1309 curve->knotVector.set1Value(iknot++,0);
1310 curve->knotVector.set1Value(iknot++,0);
1311 curve->knotVector.set1Value(iknot++,0);
1312 curve->knotVector.set1Value(iknot++,1);
1313 curve->knotVector.set1Value(iknot++,1);
1314 curve->knotVector.set1Value(iknot++,2);
1315 curve->knotVector.set1Value(iknot++,2);
1316 curve->knotVector.set1Value(iknot++,3);
1317 curve->knotVector.set1Value(iknot++,3);
1318 curve->knotVector.set1Value(iknot++,4);
1319 curve->knotVector.set1Value(iknot++,4);
1320 curve->knotVector.set1Value(iknot++,4);
1321 grp->addChild(
coord);
1322 grp->addChild(curve);
1324 grp->unrefNoDelete();
1331 SoVertexProperty *vertices =
new SoVertexProperty();
1334 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1335 for (
int i = 1; i < numnodes; i++)
1337 vertices->vertex.set1Value(iver++,
1338 cos(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusX,
1339 sin(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusY,0.0);
1341 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1343 SoLineSet * ellipse =
new SoLineSet();
1344 ellipse->numVertices = iver;
1345 ellipse->vertexProperty = vertices;
1353 if (!path||!commonBranchPoint||!newtail)
1357 sa.setInterest(SoSearchAction::FIRST);
1358 sa.setNode(newtail);
1359 sa.apply(commonBranchPoint);
1362 SoPath * newpath = sa.getPath();
1366 for (
int i=0;i<path->getLength();++i) {
1367 if (path->getNode(i)==commonBranchPoint) {
1369 path->truncate(i+1);
1374 path->append(newpath);
1386 buffer = (
char *)realloc(bufptr, size);
1395 buffer = (
char *)malloc(1024);
1399 SoWriteAction wa(&out);
1410 SoToVRML2Action vwa;
1413 SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
1416 out.openFile(qPrintable(filename));
1417 out.setHeaderString(
"#VRML V2.0 utf8");
1418 SoWriteAction wra(&out);
1433 root->unrefNoDelete();
1435 QFile
data(filename);
1436 if (
data.open(QFile::WriteOnly | QFile::Truncate)) {
1437 QTextStream out(&
data);
1438#if QTCORE_VERSION >= 0x050E00
1439 out << s << Qt::endl;
1454 if (!in.openFile(filename.toStdString().c_str()))
1456 return SoDB::readAll(&in);
1468 root->unrefNoDelete();
1486 const double& brightness,
const double& transp )
1494 const double& brightness,
const double& transp )
1496 setMatColor( m, col.redF(), col.greenF(), col.blueF(), brightness, transp);
1529 "purpose of getting supported line widths and point sizes!");
1533 SbVec2f range;
float granularity;
1534 ra->getLineWidthLimits(range, granularity);
1536 range.getValue(
a,b);
1540 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined line widths supported by hardware (min,max,granularity) = ("
1542 ra->getPointSizeLimits(range, granularity);
1543 range.getValue(
a,b);
1547 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined point sizes supported by hardware (min,max,granularity) = ("
1574 slider->setRange(0,nsteps);
1575 slider->setSingleStep(1);
1576 slider->setPageStep(stepsPerUnit);
1586 int nsteps = std::min(1000,std::max<int>(0,
1588 int stepsPerUnit = std::min(nsteps,std::max<int>(1,
1590 slider->setRange(0,nsteps);
1591 slider->setSingleStep(1);
1592 slider->setPageStep(stepsPerUnit);
1602 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1604 if (slider->value()!=itarget)
1605 slider->setValue(itarget);
1615 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1617 if (slider->value()!=itarget)
1618 slider->setValue(itarget);
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
C++23-compatible byteswap()
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
constexpr T byteswap(T value) noexcept
Reverse the bytes in n.