diff --git a/src/Camera.cc b/src/Camera.cc index 19c03c51..60b19d95 100644 --- a/src/Camera.cc +++ b/src/Camera.cc @@ -1,5 +1,6 @@ #include "Camera.h" #include "rendersettings.h" +#include "printutils.h" Camera::Camera(enum CameraType camtype) : type(camtype), projection(Camera::PERSPECTIVE), fov(45), height(60), viewall(false) diff --git a/src/export_png.cc b/src/export_png.cc index a0b8aff6..befdda4e 100644 --- a/src/export_png.cc +++ b/src/export_png.cc @@ -15,12 +15,14 @@ static void setupCamera(Camera &cam, const BoundingBox &bbox, float scalefactor) { + PRINTDB("setupCamera() %i",cam.type); if (cam.type == Camera::NONE) cam.viewall = true; if (cam.viewall) cam.viewAll(bbox, scalefactor); } void export_png(const Geometry *root_geom, Camera &cam, std::ostream &output) { + PRINTD("export_png geom"); OffscreenView *glview; try { glview = new OffscreenView(cam.pixel_width, cam.pixel_height); @@ -50,6 +52,7 @@ enum Previewer { OPENCSG, THROWNTOGETHER } previewer; void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Previewer previewer = OPENCSG) { + PRINTD("export_png_preview_common"); CsgInfo csgInfo = CsgInfo(); if (!csgInfo.compile_chains(tree)) { fprintf(stderr,"Couldn't initialize CSG chains\n"); @@ -88,6 +91,7 @@ void export_png_preview_common(Tree &tree, Camera &cam, std::ostream &output, Pr void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) { + PRINTD("export_png_w_opencsg"); #ifdef ENABLE_OPENCSG export_png_preview_common(tree, cam, output, OPENCSG); #else @@ -97,6 +101,7 @@ void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) void export_png_with_throwntogether(Tree &tree, Camera &cam, std::ostream &output) { + PRINTD("export_png_w_thrown"); export_png_preview_common(tree, cam, output, THROWNTOGETHER); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2126fdb..fc18012c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1201,8 +1201,8 @@ add_cmdline_test(throwntogethertest EXE ${OPENSCAD_BINPATH} ARGS --preview=throw add_cmdline_test(cgalstlsanitytest EXE ${CMAKE_SOURCE_DIR}/cgalstlsanitytest SUFFIX txt ARGS ${OPENSCAD_BINPATH} FILES ${CGALSTLSANITYTEST_FILES}) # Export/Import 3d png tests. -add_cmdline_test(stlpngtest EXE ${PYTHON_EXECUTABLE} SCRIPT ${CMAKE_SOURCE_DIR}/test_3d_export.py ARGS ${OPENSCAD_BINPATH} STL SUFFIX png FILES ${EXPORT3D_TEST_FILES}) -add_cmdline_test(offpngtest EXE ${PYTHON_EXECUTABLE} SCRIPT ${CMAKE_SOURCE_DIR}/test_3d_export.py ARGS ${OPENSCAD_BINPATH} OFF SUFFIX png FILES ${EXPORT3D_TEST_FILES}) +add_cmdline_test(stlpngtest EXE ${PYTHON_EXECUTABLE} SCRIPT ${CMAKE_SOURCE_DIR}/export_import_pngtest.py ARGS --openscad=${OPENSCAD_BINPATH} --format=STL SUFFIX png FILES ${EXPORT3D_TEST_FILES}) +add_cmdline_test(offpngtest EXE ${PYTHON_EXECUTABLE} SCRIPT ${CMAKE_SOURCE_DIR}/export_import_pngtest.py ARGS --openscad=${OPENSCAD_BINPATH} --format=OFF SUFFIX png FILES ${EXPORT3D_TEST_FILES}) # Add experimental tests diff --git a/tests/diffpng.cpp b/tests/diffpng.cpp index cf7c7581..4b3a84c9 100644 --- a/tests/diffpng.cpp +++ b/tests/diffpng.cpp @@ -98,12 +98,16 @@ using namespace std; class RGBAImage { public: - RGBAImage(const RGBAImage &); - RGBAImage &operator=(const RGBAImage &); + RGBAImage(const RGBAImage &img) { + Width = img.Width; + Height = img.Height; + Name = img.Name; + Data = img.Data; + }; unsigned int Width; unsigned int Height; - const string Name; + string Name; vector Data; RGBAImage(unsigned int w, unsigned int h, const string &name="") @@ -1076,6 +1080,30 @@ bool Yee_Compare_Engine(CompareArgs &args) return false; } +void copy( diffpng::RGBAImage &dest, diffpng::RGBAImage &src) { + dest.Data.clear(); + dest.Data.resize( src.Data.size() ); + for (unsigned i=0;iShift(xshift,yshift); + args.ImgB->DownSample(); + args.ImgB->SimpleBlur(); + args.ImgB->SimpleBlur(); + bool test = Yee_Compare_Engine( args ); + if (args.ImgDiff) args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name()+".diffshift1.png"); + cout << "result: " << test << "\n"; + copy(*args.ImgB, originalB); + return test; +} + /* Multi-stage comparison. @@ -1120,8 +1148,8 @@ bool LevelClimberCompare(CompareArgs &args) { while (test==false && args.MaxPyramidLevelsWriteToFile(args.ImgDiff->Get_Name()+".diff.maxlevel"+s.str()+".png"); @@ -1135,6 +1163,8 @@ bool LevelClimberCompare(CompareArgs &args) { } } + diffpng::RGBAImage originalA(*args.ImgA); + diffpng::RGBAImage originalB(*args.ImgB); // the purpose of downsampling is not necessarily to throw away pixels. // it is to enable the higher pyramid levels to run at a @@ -1142,7 +1172,6 @@ bool LevelClimberCompare(CompareArgs &args) { if (test==false) { cout << "\nTests detected differences at final max pyramid level. \n"; cout << "Retesting with downsampling and simple blur\n\n"; - args.ImgA->DownSample(); args.ImgB->DownSample(); args.ImgA->SimpleBlur(); @@ -1160,36 +1189,51 @@ bool LevelClimberCompare(CompareArgs &args) { } args.ColorFactor = 0.05; cout << "Testing with Max Pyramid Levels=" << args.MaxPyramidLevels << "\n"; - test |= Yee_Compare_Engine( args ); - cout << "Result:" << test << " : " << args.ErrorStr << "\n"; + test = Yee_Compare_Engine( args ); + cout << "Result: " << test << " ErrorStr:" << args.ErrorStr << "\n"; if (args.ImgDiff) args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name()+".diff.sampleddown.png"); + if (test) return true; }; + copy(*args.ImgA, originalA); + copy(*args.ImgB, originalB); + args.ImgA->DownSample(); + args.ImgA->SimpleBlur(); + args.ImgA->SimpleBlur(); + if (args.ImgDiff) args.ImgDiff->DownSample(); + if (test==false) { args.ColorFactor = 0.01; cout << "\nTests detected differences after downsample. \n"; cout << "Retesting with small pixel shifts\n"; - args.ImgB->Shift(-1,0); - args.ImgB->WriteToFile( "shift1.png" ); - test |= Yee_Compare_Engine( args ); - if (args.ImgDiff) args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name()+".diffshift1.png"); - cout << "result:" << test << " : " << args.ErrorStr << "\n"; - args.ImgB->Shift(2,0); - args.ImgB->WriteToFile( "shift2.png" ); - test |= Yee_Compare_Engine( args ); - if (args.ImgDiff) args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name()+".diffshift2.png"); - cout << "result:" << test << " : " << args.ErrorStr << "\n"; - args.ImgB->Shift(-1,-1); - args.ImgB->WriteToFile( "shift3.png" ); - test |= Yee_Compare_Engine( args ); - if (args.ImgDiff) args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name()+".diffshift3.png"); - cout << "result:" << test << " : " << args.ErrorStr << "\n"; - args.ImgB->Shift(0,2); - args.ImgB->WriteToFile( "shift4.png" ); - test |= Yee_Compare_Engine( args ); - if (args.ImgDiff) args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name()+".diffshift4.png"); - cout << "result:" << test << " : " << args.ErrorStr << "\n"; + + if (ShiftAndTest(args, originalB, -2, 0)) return true; + if (ShiftAndTest(args, originalB, 2, 0)) return true; + if (ShiftAndTest(args, originalB, 0,-2)) return true; + if (ShiftAndTest(args, originalB, 0, 2)) return true; + + + if (ShiftAndTest(args, originalB, -1, 0)) return true; + if (ShiftAndTest(args, originalB, 1, 0)) return true; + if (ShiftAndTest(args, originalB, 0,-1)) return true; + if (ShiftAndTest(args, originalB, 0, 1)) return true; + +/* + if (ShiftAndTest(args, originalB, -2, 2)) return true; + if (ShiftAndTest(args, originalB, 2, 2)) return true; + if (ShiftAndTest(args, originalB, 2,-2)) return true; + if (ShiftAndTest(args, originalB, 2, 2)) return true; +*/ + +/* + if (ShiftAndTest(args, originalB, -1,-1)) return true; + if (ShiftAndTest(args, originalB, 1,-1)) return true; + if (ShiftAndTest(args, originalB, -1, 1)) return true; + if (ShiftAndTest(args, originalB, 1, 1)) return true; + +*/ + } return test; }