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>
48#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;
139 const bool swapFlag = std::endian::native == std::endian::little;
142 fprintf(stderr,
"Out of memory!\n");
145 if (!(image->file = fopen(fileName,
"rb"))) {
151 int bytesRead = fread(image, 1, 12, image->file);
153 if (bytesRead != 12) {
154 fprintf(stderr,
"fread failed!\n");
174 const unsigned int colourBuffSize=image->xsize*256u;
175 image->tmp = ucharAddress(malloc(colourBuffSize));
176 image->tmpR = ucharAddress(malloc(colourBuffSize));
177 image->tmpG = ucharAddress(malloc(colourBuffSize));
178 image->tmpB = ucharAddress(malloc(colourBuffSize));
179 if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
180 image->tmpB == NULL) {
181 fprintf(stderr,
"Out of memory!\n");
186 if ((image->type & 0xFF00) == 0x0100) {
187 size_t x = ((size_t)image->ysize * (size_t)image->zsize) *
sizeof(
unsigned);
190 image->rowStart = (
unsigned *)malloc(
x);
191 image->rowSize = (
int *)malloc(
x);
192 if (image->rowStart == NULL || image->rowSize == NULL) {
193 fprintf(stderr,
"Out of memory!\n");
196 image->rleEnd = 512 + (2 *
x);
197 const int fseekRetVal= fseek(image->file, 512, SEEK_SET);
198 if (fseekRetVal !=0){
199 fprintf(stderr,
"Something very wrong with fseek near line 205 of VP1QtInventorUtils.cxx");
201 size_t bytesRead = 0;
202 bytesRead = fread(image->rowStart, 1,
x, image->file);
204 bytesRead = fread(image->rowSize, 1,
x, image->file);
209 ConvertLong((
unsigned *)image->rowSize,
x/(
int)
sizeof(
int));
212 image->rowStart = NULL;
213 image->rowSize = NULL;
225 free(image->rowSize);
226 free(image->rowStart);
231 unsigned char *buf,
int y,
int z)
233 unsigned char *iPtr, *oPtr,
pixel;
237 if ((image->type & 0xFF00) == 0x0100) {
239 int okseek = fseek(image->file, (
long)image->rowStart[
y+
z*image->ysize], SEEK_SET);
240 int okread = fread(image->tmp, 1, (
unsigned int)image->rowSize[
y+
z*image->ysize],
265 const unsigned int yDim(
y*image->xsize), zDim(
z*image->xsize*image->ysize);
266 int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
269 size_t bytesRead = 0;
270 bytesRead = fread(buf, 1, image->xsize, image->file);
276 std::cout <<
"Warning! ImageGetRow() - no 'image'..." << std::endl;
282 unsigned *
base, *lptr;
283 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
292 (*width)=image->xsize;
293 (*height)=image->ysize;
294 (*components)=image->zsize;
295 const unsigned int imageWidth = image->xsize;
296 const unsigned int imageHeight = image->ysize;
297 const unsigned int uintSize(
sizeof(
unsigned)), ucharSize(
sizeof(
unsigned char));
298 const unsigned int colourBufSize=imageWidth*ucharSize;
299 base =
reinterpret_cast<unsigned *
>(malloc(imageWidth*imageHeight*uintSize));
300 rbuf = ucharAddress(malloc(colourBufSize));
301 gbuf = ucharAddress(malloc(colourBufSize));
302 bbuf = ucharAddress(malloc(colourBufSize));
303 abuf = ucharAddress(malloc(colourBufSize));
304 if(!
base || !rbuf || !gbuf || !bbuf) {
307 if (rbuf) free(rbuf);
308 if (gbuf) free(gbuf);
309 if (bbuf) free(bbuf);
310 if (abuf) free(abuf);
314 for (
y=0;
y<image->ysize; ++
y) {
315 if (image->zsize>=4) {
322 rgbatorgba(rbuf,gbuf,bbuf,abuf,ucharAddress(lptr),image->xsize);
323 lptr += image->xsize;
324 }
else if(image->zsize==3) {
328 rgbtorgba(rbuf,gbuf,bbuf,ucharAddress(lptr),image->xsize);
329 lptr += image->xsize;
330 }
else if(image->zsize==2) {
333 latorgba(rbuf,abuf,ucharAddress(lptr),image->xsize);
334 lptr += image->xsize;
337 bwtorgba(rbuf,ucharAddress(lptr),image->xsize);
338 lptr += image->xsize;
347 return (
unsigned *)
base;
402 constexpr int maxheight(10'000);
403 constexpr int maxwidth(10'000);
404 auto inbounds = [](
int w,
int h)->
bool{
405 return (w>0 and w<maxwidth) and (
h>0 and
h<maxheight);
408 if( not inbounds(
width, height)){
409 std::cout <<
"VP1QtInventorUtils::imageFromRGBFile - read_texture failed?" << std::endl;
411 height = std::clamp(height, 0, maxheight);
413 unsigned char *
data =
reinterpret_cast<unsigned char*
>(imagedata);
415 QImage im(
width,height, ( components <= 3 ? QImage::Format_RGB32 : QImage::Format_ARGB32 ) );
418 for (;
y<height; ++
y) {
433 bool transparent_background,
double actualRenderedSizeFact )
446 if (actualRenderedSizeFact!=1.0&&!transparent_background) {
448 static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
449 static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
452 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
455 if (transparent_background) {
460 SbColor save_bgd = ra->getBackgroundColor();
461 SbBool save_redraw = ra->isAutoRedraw();
463 ra->setAutoRedraw(
false);
466 QImage im_black_bgd, im_white_bgd;
467 if (actualRenderedSizeFact==1.0) {
468 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
469 im_black_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
470 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
471 im_white_bgd =
renderToImage(ra, pixels_x, pixels_y,
false,1.0);
473 ra->setBackgroundColor(SbColor(0.0,0.0,0.0));
474 im_black_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
475 ra->setBackgroundColor(SbColor(1.0,1.0,1.0));
476 im_white_bgd =
renderToImage(ra,
static_cast<int>(pixels_x*actualRenderedSizeFact+0.5),
static_cast<int>(pixels_y*actualRenderedSizeFact+0.5),
false,1.0);
479 ra->setBackgroundColor(save_bgd);
480 ra->setAutoRedraw(save_redraw);
482 if (actualRenderedSizeFact==1.0)
486 .scaled(pixels_x,pixels_y,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
503 SoNode *rootOverlay = ra->getOverlaySceneGraph();
508 SbViewportRegion myViewport;
509 myViewport.setWindowSize(SbVec2s(pixels_x,pixels_y));
511 QString tmppath(QDir::tempPath());
512 if (!tmppath.endsWith(QDir::separator()))
513 tmppath+=QDir::separator();
514 tmppath +=
"vp1tmpfileXXXXXX.rgb";
515 std::string stmppath = tmppath.toStdString();
516 int tmpfd = mkstemps (stmppath.data(), 4);
517 FILE* tmpf = fdopen (tmpfd,
"w");
518 QString tmpfile (stmppath.c_str());
521 SoOffscreenRenderer *myRenderer =
new SoOffscreenRenderer(myViewport);
524 myRenderer->setBackgroundColor(ra->getBackgroundColor());
527 myRenderer->setComponents(SoOffscreenRenderer::RGB_TRANSPARENCY);
528 myRenderer->getGLRenderAction()->setTransparencyType(ra->getTransparencyType());
532 SbBool smoothing;
int numPasses;
533 ra->getAntialiasing (smoothing, numPasses);
534 myRenderer->getGLRenderAction()->setSmoothing (smoothing);
535 myRenderer->getGLRenderAction()->setNumPasses(numPasses);
542 if (!myRenderer->render(root)) {
552 bool okOver = myRenderer->render(rootOverlay);
565 if (!myRenderer->writeToRGB(tmpf)) {
567 if (QFile::exists(tmpfile))
568 QFile(tmpfile).remove();
582 if (QFile::exists(tmpfile))
583 QFile(tmpfile).remove();
592 bool transparent_background,
double actualRenderedSizeFact )
594 return QPixmap::fromImage(
renderToImage(ra, pixels_x, pixels_y, transparent_background, actualRenderedSizeFact));
600 if (im_black_bgd.isNull()||im_white_bgd.isNull()||im_black_bgd.size()!=im_white_bgd.size())
603 QImage im(im_black_bgd.size(),QImage::Format_ARGB32);
605 int width = im.width();
606 int height = im.height();
607 QRgb white = qRgba(255,255,255,255);
608 QRgb black = qRgba(0,0,0,255);
611 for (
int y = 0;
y < height; ++
y) {
612 if (im_black_bgd.pixel(
x,
y)==im_white_bgd.pixel(
x,
y)) {
613 im.setPixel(
x,
y,im_white_bgd.pixel(
x,
y));
614 }
else if (im_black_bgd.pixel(
x,
y)==black&&im_white_bgd.pixel(
x,
y)==white) {
615 im.setPixel(
x,
y,Qt::transparent);
618 QColor pix_b = QColor(im_black_bgd.pixel(
x,
y));
619 QColor pix_w = QColor(im_white_bgd.pixel(
x,
y));
620 qreal alpha = 1.0 - pix_w.redF() + pix_b.redF();
622 im.setPixel(
x,
y,Qt::transparent);
624 im.setPixel(
x,
y,qRgba(
static_cast<int>(pix_b.redF()/alpha*255+0.5),
625 static_cast<int>(pix_b.greenF()/alpha*255+0.5),
626 static_cast<int>(pix_b.blueF()/alpha*255+0.5),
627 static_cast<int>(alpha*255+0.5)));
639 return SoGLRenderAction::DELAYED_BLEND;
645 QList<SoGLRenderAction::TransparencyType> l;
646 l << SoGLRenderAction::NONE
647 << SoGLRenderAction::SCREEN_DOOR
648 << SoGLRenderAction::ADD
649 << SoGLRenderAction::DELAYED_ADD
650 << SoGLRenderAction::SORTED_OBJECT_ADD
651 << SoGLRenderAction::BLEND
652 << SoGLRenderAction::DELAYED_BLEND
653 << SoGLRenderAction::SORTED_OBJECT_BLEND
654 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD
655 << SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND
656 << SoGLRenderAction::SORTED_LAYERS_BLEND;
664 case SoGLRenderAction::SCREEN_DOOR:
return 0;
665 case SoGLRenderAction::ADD:
return 1;
666 case SoGLRenderAction::DELAYED_ADD:
return 2;
667 case SoGLRenderAction::SORTED_OBJECT_ADD:
return 3;
668 case SoGLRenderAction::BLEND:
return 4;
669 case SoGLRenderAction::DELAYED_BLEND:
return 5;
670 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return 6;
671 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return 7;
672 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return 8;
673 case SoGLRenderAction::NONE:
return 9;
674 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return 10;
676 VP1Msg::messageDebug(
"VP1QtInventorUtils::transparencyTypeToInt ERROR: Unknown transparency type");
684 case 0:
return SoGLRenderAction::SCREEN_DOOR;
685 case 1:
return SoGLRenderAction::ADD;
686 case 2:
return SoGLRenderAction::DELAYED_ADD;
687 case 3:
return SoGLRenderAction::SORTED_OBJECT_ADD;
688 case 4:
return SoGLRenderAction::BLEND;
689 case 5:
return SoGLRenderAction::DELAYED_BLEND;
690 case 6:
return SoGLRenderAction::SORTED_OBJECT_BLEND;
691 case 7:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD;
692 case 8:
return SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND;
693 case 9:
return SoGLRenderAction::NONE;
694 case 10:
return SoGLRenderAction::SORTED_LAYERS_BLEND;
697 return SoGLRenderAction::DELAYED_BLEND;
706 case SoGLRenderAction::DELAYED_BLEND:
return "Delayed blend";
break;
707 case SoGLRenderAction::SCREEN_DOOR:
return "Screen door";
break;
708 case SoGLRenderAction::ADD:
return "Add";
break;
709 case SoGLRenderAction::DELAYED_ADD:
return "Delayed add";
break;
710 case SoGLRenderAction::SORTED_OBJECT_ADD:
return "Sorted object add";
break;
711 case SoGLRenderAction::BLEND:
return "Blend (Best for Geo volumes)";
break;
712 case SoGLRenderAction::SORTED_OBJECT_BLEND:
return "Sorted object blend (Best for physics objects: jets, tracks, ...)";
break;
713 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD:
return "Sorted object sorted triangle add";
break;
714 case SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND:
return "Sorted object sorted triangle blend";
break;
715 case SoGLRenderAction::NONE:
return "None";
break;
716 case SoGLRenderAction::SORTED_LAYERS_BLEND:
return "Sorted layers blend";
break;
727 QByteArray byteArray;
728 QBuffer buffer(&byteArray);
729 buffer.open(QIODevice::WriteOnly);
730 QDataStream out(&buffer);
735 rot.getValue (q0,q1,q2,q3);
745 +QString::number(q0)+
", "+QString::number(q1)+
", "
746 +QString::number(q2)+
", "+QString::number(q3)+
")");
759 buffer.open(QIODevice::ReadOnly);
760 QDataStream state(&buffer);
764 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
772 rot.setValue (q0,q1,q2,q3);
777 +QString::number(q0)+
", "+QString::number(q1)+
", "
778 +QString::number(q2)+
", "+QString::number(q3)+
")");
790 rot.setValue (q0,q1,q2,q3);
795 +QString::number(q0)+
", "+QString::number(q1)+
", "
796 +QString::number(q2)+
", "+QString::number(q3)+
")");
810 QByteArray byteArray;
811 QBuffer buffer(&byteArray);
812 buffer.open(QIODevice::WriteOnly);
813 QDataStream out(&buffer);
825 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
838 buffer.open(QIODevice::ReadOnly);
839 QDataStream state(&buffer);
843 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
855 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
870 +QString::number(
x)+
", "+QString::number(
y)+
", "+QString::number(
z)+
")");
887 QByteArray byteArray;
888 QBuffer buffer(&byteArray);
889 buffer.open(QIODevice::WriteOnly);
890 QDataStream out(&buffer);
894 SbRotation camrot = cam.orientation.getValue();
896 SbVec3f campos = cam.position.getValue();
898 float f_aspectRatio(cam.aspectRatio.getValue());
899 float f_nearDistance(cam.nearDistance.getValue());
900 float f_farDistance(cam.farDistance.getValue());
901 float f_focalDistance(cam.focalDistance.getValue());
902 out << (double)f_aspectRatio;
903 out << (double)f_nearDistance;
904 out << (double)f_farDistance;
905 out << (double)f_focalDistance;
908 switch (cam.viewportMapping.getValue()) {
909 case SoCamera::CROP_VIEWPORT_FILL_FRAME: viewportmap = 0;
break;
910 case SoCamera::CROP_VIEWPORT_LINE_FRAME: viewportmap = 1;
break;
911 case SoCamera::CROP_VIEWPORT_NO_FRAME: viewportmap = 2;
break;
912 case SoCamera::ADJUST_CAMERA: viewportmap = 3;
break;
913 case SoCamera::LEAVE_ALONE: viewportmap = 4;
break;
919 if (cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId()))
921 else if (cam.getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId()))
926 out << (double)static_cast<const SoPerspectiveCamera*>(&cam)->heightAngle.getValue();
927 }
else if (camtype==1) {
928 out << (double)static_cast<const SoOrthographicCamera*>(&cam)->height.getValue();
937 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
938 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
939 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
940 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
941 VP1Msg::messageVerbose(
"VP1QtInventorUtils::serializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
943 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
946 +QString::number(
static_cast<const SoPerspectiveCamera*
>(&cam)->heightAngle.getValue()));
949 +QString::number(
static_cast<const SoOrthographicCamera*
>(&cam)->height.getValue()));
960 if (ba==QByteArray())
965 buffer.open(QIODevice::ReadOnly);
966 QDataStream state(&buffer);
970 state.setFloatingPointPrecision(QDataStream::SinglePrecision);
973 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
976 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
979 bool save = cam.enableNotify(
false);
981 cam.orientation.setValue(rot);
982 cam.position.setValue(pos);
984 float f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
986 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
987 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
988 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
989 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
993 switch (viewportmap) {
994 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
995 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
996 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
997 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
998 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1002 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1007 float f_orthopersp_heightpar(-999);
1010 if (!passedcameraisperspective)
1012 state >> f_orthopersp_heightpar;
1013 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1014 }
else if (camtype==1) {
1016 if (passedcameraisperspective)
1018 state >> f_orthopersp_heightpar;
1019 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1023 cam.enableNotify(
true);
1031 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1032 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1033 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1034 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1035 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1037 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1040 +QString::number(f_orthopersp_heightpar));
1043 +QString::number(f_orthopersp_heightpar));
1051 SbRotation rot; QByteArray ba_rot; state >> ba_rot;
1054 SbVec3f pos; QByteArray ba_pos; state >> ba_pos;
1057 bool save = cam.enableNotify(
false);
1059 cam.orientation.setValue(rot);
1060 cam.position.setValue(pos);
1062 double f_aspectRatio, f_nearDistance, f_farDistance, f_focalDistance;
1064 state >> f_aspectRatio; cam.aspectRatio.setValue(f_aspectRatio);
1065 state >> f_nearDistance; cam.nearDistance.setValue(f_nearDistance);
1066 state >> f_farDistance; cam.farDistance.setValue(f_farDistance);
1067 state >> f_focalDistance; cam.focalDistance.setValue(f_focalDistance);
1071 switch (viewportmap) {
1072 case 0: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_FILL_FRAME);
break;
1073 case 1: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_LINE_FRAME);
break;
1074 case 2: cam.viewportMapping.setValue(SoCamera::CROP_VIEWPORT_NO_FRAME);
break;
1075 case 3: cam.viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
break;
1076 case 4: cam.viewportMapping.setValue(SoCamera::LEAVE_ALONE);
break;
1080 bool passedcameraisperspective = cam.getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId());
1085 double f_orthopersp_heightpar(-999);
1088 if (!passedcameraisperspective)
1090 state >> f_orthopersp_heightpar;
1091 static_cast<SoPerspectiveCamera*
>(&cam)->heightAngle.setValue(f_orthopersp_heightpar);
1092 }
else if (camtype==1) {
1094 if (passedcameraisperspective)
1096 state >> f_orthopersp_heightpar;
1097 static_cast<SoOrthographicCamera*
>(&cam)->height.setValue(f_orthopersp_heightpar);
1101 cam.enableNotify(
true);
1109 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters aspectRatio = "+QString::number(f_aspectRatio));
1110 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters nearDistance = "+QString::number(f_nearDistance));
1111 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters farDistance = "+QString::number(f_farDistance));
1112 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters focalDistance = "+QString::number(f_focalDistance));
1113 VP1Msg::messageVerbose(
"VP1QtInventorUtils::deserializeSoCameraParameters viewportmap = "+QString::number(viewportmap));
1115 +QString(camtype==0?
"perspective":(camtype==1?
"orthographic":
"unknown")));
1118 +QString::number(f_orthopersp_heightpar));
1121 +QString::number(f_orthopersp_heightpar));
1126 cam.unrefNoDelete();
1134 return SbColor( col.red()/255.0, col.green()/255.0, col.blue()/255.0 );
1141 col.getValue(
r,g,b);
1142 return QColor::fromRgbF(
r,g,b );
1148 if (!m||m->ambientColor.getNum()!=1
1149 ||m->diffuseColor.getNum()!=1
1150 ||m->specularColor.getNum()!=1
1151 ||m->emissiveColor.getNum()!=1
1152 ||m->transparency.getNum()!=1
1153 ||m->shininess.getNum()!=1) {
1155 "Passed material must have exactly one value in each of the 6 fields!!");
1156 return QByteArray();
1161 QByteArray byteArray;
1162 QBuffer buffer(&byteArray);
1163 buffer.open(QIODevice::WriteOnly);
1164 QDataStream out(&buffer);
1167 out << QString(
"somat_v1_begin");
1172 out << (double)m->shininess[0];
1173 out << (double)m->transparency[0];
1174 out << QString(
"somat_end");
1186 if (!m||m->ambientColor.getNum()!=1
1187 ||m->diffuseColor.getNum()!=1
1188 ||m->specularColor.getNum()!=1
1189 ||m->emissiveColor.getNum()!=1
1190 ||m->transparency.getNum()!=1
1191 ||m->shininess.getNum()!=1) {
1193 "Passed material must have exactly one value in each of the 6 fields!!");
1198 QBuffer buffer(&ba);
1199 buffer.open(QIODevice::ReadOnly);
1200 QDataStream stream(&buffer);
1202 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
1205 QString
str; stream >>
str;
1206 if (
str!=
"somat_v1_begin")
1209 QColor ambientcol; stream >> ambientcol;
1210 if (!ambientcol.isValid())
1213 QColor diffusecol; stream >> diffusecol;
1214 if (!diffusecol.isValid())
1217 QColor specularcol; stream >> specularcol;
1218 if (!specularcol.isValid())
1221 QColor emissivecol; stream >> emissivecol;
1222 if (!emissivecol.isValid())
1225 if(ba.size()==106) {
1227 float shininess; stream >> shininess;
1228 if (shininess<0.0f||shininess>1.0f)
1231 float transparency; stream >> transparency;
1232 if (transparency<0.0f||transparency>1.0f)
1236 if (
str!=
"somat_end")
1242 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1243 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1244 m->specularColor.setValue(
qcol2sbcol(specularcol));
1245 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1246 m->shininess.setValue(shininess);
1247 m->transparency.setValue(transparency);
1251 double shininess; stream >> shininess;
1252 if (shininess<0.0||shininess>1.0)
1255 double transparency; stream >> transparency;
1256 if (transparency<0.0||transparency>1.0)
1260 if (
str!=
"somat_end")
1266 m->ambientColor.setValue(
qcol2sbcol(ambientcol));
1267 m->diffuseColor.setValue(
qcol2sbcol(diffusecol));
1268 m->specularColor.setValue(
qcol2sbcol(specularcol));
1269 m->emissiveColor.setValue(
qcol2sbcol(emissivecol));
1270 m->shininess.setValue(shininess);
1271 m->transparency.setValue(transparency);
1280 SoGroup* grp =
new SoGroup;
1283 SoCoordinate4 *
coord =
new SoCoordinate4;
1284 const double invsqrttwo=0.707106781186547;
1287 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1288 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1289 coord->point.set1Value(icoord++,SbVec4f(0,1*radius,0,1));
1290 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,invsqrttwo*radius,0,invsqrttwo));
1291 coord->point.set1Value(icoord++,SbVec4f(-1*radius,0,0,1));
1292 coord->point.set1Value(icoord++,SbVec4f(-invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1293 coord->point.set1Value(icoord++,SbVec4f(0,-1*radius,0,1));
1294 coord->point.set1Value(icoord++,SbVec4f(invsqrttwo*radius,-invsqrttwo*radius,0,invsqrttwo));
1295 coord->point.set1Value(icoord++,SbVec4f(1*radius,0,0,1));
1297 SoNurbsCurve * curve =
new SoNurbsCurve;
1298 curve->numControlPoints = icoord;
1302 curve->knotVector.set1Value(iknot++,0);
1303 curve->knotVector.set1Value(iknot++,0);
1304 curve->knotVector.set1Value(iknot++,0);
1305 curve->knotVector.set1Value(iknot++,1);
1306 curve->knotVector.set1Value(iknot++,1);
1307 curve->knotVector.set1Value(iknot++,2);
1308 curve->knotVector.set1Value(iknot++,2);
1309 curve->knotVector.set1Value(iknot++,3);
1310 curve->knotVector.set1Value(iknot++,3);
1311 curve->knotVector.set1Value(iknot++,4);
1312 curve->knotVector.set1Value(iknot++,4);
1313 curve->knotVector.set1Value(iknot++,4);
1314 grp->addChild(
coord);
1315 grp->addChild(curve);
1317 grp->unrefNoDelete();
1324 SoVertexProperty *vertices =
new SoVertexProperty();
1327 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1328 for (
int i = 1; i < numnodes; i++)
1330 vertices->vertex.set1Value(iver++,
1331 cos(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusX,
1332 sin(2.0*
static_cast<double>(i)*
M_PI/
static_cast<double>(numnodes))*radiusY,0.0);
1334 vertices->vertex.set1Value(iver++,radiusX,0.0,0.0);
1336 SoLineSet * ellipse =
new SoLineSet();
1337 ellipse->numVertices = iver;
1338 ellipse->vertexProperty = vertices;
1346 if (!path||!commonBranchPoint||!newtail)
1350 sa.setInterest(SoSearchAction::FIRST);
1351 sa.setNode(newtail);
1352 sa.apply(commonBranchPoint);
1355 SoPath * newpath = sa.getPath();
1359 for (
int i=0;i<path->getLength();++i) {
1360 if (path->getNode(i)==commonBranchPoint) {
1362 path->truncate(i+1);
1367 path->append(newpath);
1388 buffer = (
char *)malloc(1024);
1392 SoWriteAction wa(&out);
1403 SoToVRML2Action vwa;
1406 SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
1409 out.openFile(qPrintable(filename));
1410 out.setHeaderString(
"#VRML V2.0 utf8");
1411 SoWriteAction wra(&out);
1426 root->unrefNoDelete();
1428 QFile
data(filename);
1429 if (
data.open(QFile::WriteOnly | QFile::Truncate)) {
1430 QTextStream out(&
data);
1431#if QTCORE_VERSION >= 0x050E00
1432 out << s << Qt::endl;
1447 if (!in.openFile(filename.toStdString().c_str()))
1449 return SoDB::readAll(&in);
1461 root->unrefNoDelete();
1479 const double& brightness,
const double& transp )
1487 const double& brightness,
const double& transp )
1489 setMatColor( m, col.redF(), col.greenF(), col.blueF(), brightness, transp);
1522 "purpose of getting supported line widths and point sizes!");
1526 SbVec2f range;
float granularity;
1527 ra->getLineWidthLimits(range, granularity);
1529 range.getValue(
a,b);
1533 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined line widths supported by hardware (min,max,granularity) = ("
1535 ra->getPointSizeLimits(range, granularity);
1536 range.getValue(
a,b);
1540 VP1Msg::messageVerbose(
"VP1QtInventorUtils Determined point sizes supported by hardware (min,max,granularity) = ("
1567 slider->setRange(0,nsteps);
1568 slider->setSingleStep(1);
1569 slider->setPageStep(stepsPerUnit);
1579 int nsteps = std::min(1000,std::max<int>(0,
1581 int stepsPerUnit = std::min(nsteps,std::max<int>(1,
1583 slider->setRange(0,nsteps);
1584 slider->setSingleStep(1);
1585 slider->setPageStep(stepsPerUnit);
1595 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1597 if (slider->value()!=itarget)
1598 slider->setValue(itarget);
1608 int itarget = std::min(slider->maximum(),std::max<int>(slider->minimum(),
1610 if (slider->value()!=itarget)
1611 slider->setValue(itarget);
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
size_t size() const
Number of registered mappings.
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.