diff --git a/CMakeLists.txt b/CMakeLists.txt index 19f7b04..d3ca3c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,6 @@ set_target_properties(poncaplot PROPERTIES RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_ # Fix compilation error with MSVC if (MSVC) - target_compile_options(poncaplot PRIVATE /bigobj) + target_compile_options(poncaplot PRIVATE /bigobj -openmp:llvm) endif () diff --git a/README.md b/README.md index bb66883..81136fd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # poncaplot -2d plot application displaying scalar/vector fields reconstructed using Ponca -![image](https://github.com/poncateam/poncaplot/assets/6310221/75ad8c69-98af-43b7-9148-7123319b2760) -![image](https://github.com/poncateam/poncaplot/assets/6310221/b1b388b3-ad28-47d1-9f20-a44ab19ad796) +2d plot application displaying scalar fields reconstructed using [Ponca](https://poncateam.github.io/ponca/) + + + + +https://github.com/poncateam/poncaplot/assets/6310221/a1885def-4135-4afa-b833-f2968697586f + diff --git a/dataset/bunny.dat b/dataset/bunny.dat index 2608478..6ca9a37 100644 --- a/dataset/bunny.dat +++ b/dataset/bunny.dat @@ -1,129 +1,129 @@ # x y nx ny -228.969 18.6691 -0.142503 -0.989794 -214.614 20.8804 -0.271324 -0.962488 -201.227 26.4899 -0.270028 -0.962853 -187.027 28.6103 -0.024168 -0.999708 -172.552 27.1909 0.119336 -0.992854 -158.155 25.1401 0.0932225 -0.995645 -143.624 24.4823 -0.0251171 -0.999685 -129.198 25.8689 -0.285292 -0.958441 -116.491 32.5679 -0.917162 -0.398515 -114.078 46.0523 -0.986312 -0.164892 -113.047 58.3086 -0.933771 -0.357872 -107.169 70.0382 -0.998194 0.0600762 -114.214 82.7168 -0.779438 0.626479 -124.976 92.1766 -0.533188 0.845997 -138.334 97.9326 -0.602708 0.797962 -146.754 108.722 -0.99998 0.00636636 -136.929 115.636 -0.410366 -0.911921 -122.925 119.605 -0.320878 -0.947121 -109.408 124.96 -0.482556 -0.875865 -97.7304 133.49 -0.619289 -0.785163 -86.6565 142.904 -0.69817 -0.715932 -76.9588 153.746 -0.856326 -0.516435 -67.5209 164.833 -0.824662 -0.565626 - 60.66 177.532 -0.827018 -0.562176 - 54.496 190.655 -0.962354 -0.271799 -49.2984 204.147 -0.982173 0.187981 -49.1295 218.672 -0.99896 0.0456026 -50.6214 233.132 -0.97224 0.233986 -55.1744 246.216 -0.976651 -0.214833 -44.1788 252.743 -0.525772 -0.850626 -32.4983 261.072 -0.75969 -0.650286 -24.9319 273.362 -0.952743 0.303779 - 23.986 287.768 -0.995882 0.0906624 -27.5213 301.856 -0.968207 0.25015 -31.2583 315.916 -0.977588 0.210529 - 33.64 330.268 -0.986761 0.162181 -35.9799 344.644 -0.999184 0.0403894 -34.8005 359.07 -0.993444 0.114323 -39.2236 372.802 -0.83245 0.5541 -50.1519 382.122 -0.505101 0.86306 -63.7849 387.189 -0.294318 0.955707 -77.9122 390.671 -0.251752 0.967792 -91.3056 394.351 -0.780164 0.625575 -92.7628 408.839 -0.994975 0.100121 -94.2209 423.323 -0.986009 0.166691 -97.5992 437.442 -0.935884 0.352308 -104.321 450.132 -0.704323 0.709879 -117.155 456.866 -0.210798 0.97753 -131.551 455.997 0.355984 0.934492 -144.143 448.292 0.844111 0.536168 -146.473 433.199 0.996914 -0.0785065 - 144.98 418.774 0.90178 0.432195 -139.837 405.185 0.516433 0.856328 -146.181 405.872 -0.234265 0.972173 -157.091 415.51 -0.29162 0.956534 -167.883 425.279 -0.652211 0.758038 -179.147 434.487 -0.608992 0.793177 -190.953 442.992 -0.560781 0.827964 -203.241 450.806 -0.535292 0.844667 -215.504 458.55 -0.548279 0.836296 -227.544 466.739 -0.545749 0.837949 -239.897 474.438 -0.41457 0.910017 -253.418 478.504 0.196699 0.980464 - 264.74 469.527 0.764407 0.644734 -271.739 456.915 0.822954 0.568108 -274.838 442.769 0.995683 -0.0928154 -274.414 428.243 0.969379 -0.245568 -267.912 415.501 0.783857 -0.620942 -256.868 406.07 0.559931 -0.828539 -243.988 399.333 0.437505 -0.899216 -230.716 393.346 0.40087 -0.916135 -217.332 387.669 0.431133 -0.902288 -204.507 380.823 0.469868 -0.882737 -191.649 373.998 0.491561 -0.870843 -179.188 366.531 0.530932 -0.847414 -167.035 358.577 0.824017 -0.566565 - 164.58 345.056 0.995925 -0.0901891 -169.426 331.373 0.998315 0.0580234 -178.374 319.982 0.574449 0.81854 -192.019 315.535 0.288952 0.957344 -206.017 311.637 0.273907 0.961756 -219.951 307.58 0.09506 0.995472 - 234.37 308.931 -0.169144 0.985591 -248.477 312.474 -0.24806 0.968745 -262.565 316.151 -0.243243 0.969965 -276.718 319.556 -0.204287 0.978911 -291.036 322.092 -0.121988 0.992532 -305.553 323.101 -0.0368414 0.999321 -320.104 323.164 0.0386137 0.999254 -334.569 321.979 0.214754 0.976668 -348.227 316.981 0.393408 0.919364 -361.282 310.548 0.47724 0.878773 -373.783 303.103 0.567348 0.823478 -385.183 294.081 0.659128 0.75203 -395.877 284.838 0.725596 0.688121 -404.893 272.733 0.742014 0.670385 - 413.06 260.701 0.832799 0.553575 -420.705 248.285 0.958039 0.286638 -425.819 234.605 0.852343 0.522983 - 431.05 220.008 0.978726 0.205173 -432.721 206.391 0.988524 -0.151062 -434.553 191.957 0.9943 -0.106623 -435.824 177.454 0.998241 -0.0592836 -436.265 163.099 0.68304 0.730381 -450.814 163.261 0.170737 0.985317 -464.132 158.249 0.605563 0.795797 -473.121 146.902 0.939887 0.341486 -474.213 132.334 0.999997 -0.0025838 -472.654 117.864 0.979425 -0.201807 -468.376 104.012 0.895933 -0.44419 -459.942 92.2238 0.748117 -0.663567 -449.223 82.4162 0.619113 -0.785302 -437.176 74.275 0.516586 -0.856235 -424.354 67.4126 0.427279 -0.90412 -410.904 61.8593 0.346664 -0.937989 -397.089 57.3358 0.299092 -0.954224 -383.158 53.1626 0.505331 -0.862926 -372.752 43.0794 0.65725 -0.753672 -361.382 34.173 0.458552 -0.888668 -347.475 30.0311 0.221991 -0.975049 -333.107 27.7349 0.133278 -0.991079 - 318.63 26.1521 0.101192 -0.994867 -304.152 24.7898 0.096887 -0.995295 -289.656 23.3317 0.103085 -0.994673 -275.184 21.7876 0.107156 -0.994242 -260.722 20.2132 0.105711 -0.994397 -246.242 18.7108 0.0588211 -0.998269 -231.711 18.5042 0.00632855 -0.99998 +271.031 481.331 -0.142503 -0.989794 +285.386 479.12 -0.271324 -0.962488 +298.773 473.51 -0.270028 -0.962853 +312.973 471.39 -0.024168 -0.999708 +327.448 472.809 0.119336 -0.992854 +341.845 474.86 0.0932226 -0.995645 +356.376 475.518 -0.0251171 -0.999685 +370.802 474.131 -0.285292 -0.958441 +383.509 467.432 -0.917162 -0.398515 +385.922 453.948 -0.986312 -0.164892 +386.953 441.691 -0.933771 -0.357872 +392.831 429.962 -0.998194 0.0600762 +385.786 417.283 -0.779438 0.626479 +375.024 407.823 -0.533188 0.845997 +361.666 402.067 -0.602708 0.797962 +353.246 391.278 -0.99998 0.00636636 +363.071 384.364 -0.410366 -0.911921 +377.075 380.395 -0.320878 -0.947121 +390.592 375.04 -0.482556 -0.875865 +402.27 366.51 -0.619289 -0.785163 +413.344 357.096 -0.69817 -0.715932 +423.041 346.254 -0.856326 -0.516435 +432.479 335.167 -0.824662 -0.565626 + 439.34 322.468 -0.827018 -0.562176 +445.504 309.345 -0.962354 -0.271799 +450.702 295.853 -0.982173 0.187981 +450.871 281.328 -0.99896 0.0456026 +449.379 266.868 -0.97224 0.233986 +444.826 253.784 -0.976651 -0.214833 +455.821 247.257 -0.525772 -0.850626 +467.502 238.928 -0.75969 -0.650286 +475.068 226.638 -0.952743 0.303779 +476.014 212.232 -0.995882 0.0906624 +472.479 198.144 -0.968207 0.25015 +468.742 184.084 -0.977588 0.210529 + 466.36 169.732 -0.986761 0.162181 + 464.02 155.356 -0.999184 0.0403894 + 465.2 140.93 -0.993444 0.114323 +460.777 127.198 -0.83245 0.5541 +449.848 117.878 -0.505101 0.86306 +436.215 112.811 -0.294318 0.955707 +422.088 109.329 -0.251752 0.967792 +408.695 105.649 -0.780164 0.625575 +407.237 91.1608 -0.994975 0.100121 +405.779 76.6768 -0.986009 0.166691 +402.401 62.5578 -0.935884 0.352308 +395.679 49.8678 -0.704323 0.709879 +382.845 43.1338 -0.210798 0.97753 +368.449 44.0028 0.355984 0.934492 +355.857 51.7078 0.844111 0.536168 +353.527 66.8008 0.996914 -0.0785065 + 355.02 81.2258 0.90178 0.432195 +360.163 94.8148 0.516433 0.856328 +353.819 94.1278 -0.234265 0.972173 +342.909 84.4898 -0.29162 0.956534 +332.117 74.7208 -0.652211 0.758038 +320.853 65.5128 -0.608992 0.793177 +309.047 57.0078 -0.560781 0.827964 +296.759 49.1938 -0.535292 0.844667 +284.496 41.4498 -0.548279 0.836296 +272.456 33.2608 -0.545749 0.837949 +260.103 25.5618 -0.41457 0.910017 +246.582 21.4958 0.196699 0.980464 + 235.26 30.4728 0.764407 0.644734 +228.261 43.0848 0.822954 0.568108 +225.162 57.2308 0.995683 -0.0928154 +225.586 71.7568 0.969379 -0.245568 +232.088 84.4988 0.783857 -0.620942 +243.132 93.9298 0.559931 -0.828539 +256.012 100.667 0.437505 -0.899216 +269.284 106.654 0.40087 -0.916135 +282.668 112.331 0.431133 -0.902288 +295.493 119.177 0.469868 -0.882737 +308.351 126.002 0.491561 -0.870843 +320.812 133.469 0.530932 -0.847414 +332.965 141.423 0.824017 -0.566565 + 335.42 154.944 0.995925 -0.0901891 +330.574 168.627 0.998315 0.0580234 +321.626 180.018 0.574449 0.81854 +307.981 184.465 0.288952 0.957344 +293.983 188.363 0.273907 0.961756 +280.049 192.42 0.09506 0.995472 + 265.63 191.069 -0.169144 0.985591 +251.523 187.526 -0.24806 0.968745 +237.435 183.849 -0.243243 0.969965 +223.282 180.444 -0.204287 0.978911 +208.964 177.908 -0.121988 0.992532 +194.447 176.899 -0.0368414 0.999321 +179.896 176.836 0.0386137 0.999254 +165.431 178.021 0.214754 0.976668 +151.773 183.019 0.393408 0.919364 +138.718 189.452 0.47724 0.878773 +126.217 196.897 0.567348 0.823478 +114.817 205.919 0.659128 0.75203 +104.123 215.162 0.725596 0.688121 +95.1071 227.267 0.742014 0.670385 + 86.94 239.299 0.832799 0.553575 + 79.295 251.715 0.958039 0.286638 + 74.181 265.395 0.852343 0.522983 + 68.95 279.992 0.978726 0.205173 + 67.279 293.609 0.988524 -0.151062 + 65.447 308.043 0.9943 -0.106623 + 64.176 322.546 0.998241 -0.0592836 + 63.735 336.901 0.68304 0.730381 + 49.186 336.739 0.170737 0.985317 + 35.868 341.751 0.605563 0.795797 + 26.879 353.098 0.939887 0.341486 + 25.787 367.666 0.999997 -0.0025838 + 27.346 382.136 0.979425 -0.201807 + 31.624 395.988 0.895933 -0.44419 + 40.058 407.776 0.748117 -0.663567 + 50.777 417.584 0.619113 -0.785302 + 62.824 425.725 0.516586 -0.856235 + 75.646 432.587 0.427279 -0.90412 +89.0961 438.141 0.346664 -0.937989 +102.911 442.664 0.299092 -0.954224 +116.842 446.837 0.505331 -0.862926 +127.248 456.921 0.65725 -0.753672 +138.618 465.827 0.458552 -0.888668 +152.525 469.969 0.221991 -0.975049 +166.893 472.265 0.133278 -0.991079 + 181.37 473.848 0.101192 -0.994867 +195.848 475.21 0.0968871 -0.995295 +210.344 476.668 0.103085 -0.994673 +224.816 478.212 0.107156 -0.994242 +239.278 479.787 0.105711 -0.994397 +253.758 481.289 0.058821 -0.998269 +268.289 481.496 0.0063285 -0.99998 diff --git a/src/application.cpp b/src/application.cpp index b9a4c7a..febf97c 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -28,7 +28,7 @@ const int tex_width = 500; const int tex_height = 500; PoncaPlotApplication::PoncaPlotApplication() : -Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ +Screen(Vector2i(1200, 1024), "PoncaPlot"), m_dataMgr(new DataManager()){ m_dataMgr->setKdTreePostUpdateFunction([this]() { this->renderPasses(); }); @@ -38,13 +38,14 @@ Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ passOrientedSphereFit = new OrientedSphereFitField(); passUnorientedSphereFit = new UnorientedSphereFitField(); - m_passes[0] = new FillPass( {255,255,255,255}); - m_passes[1] = passDFWithKdTree; - m_passes[2] = new DisplayPoint({255,0,0,255}); + m_passes[0] = new FillPass( {1,1,1,1}); + m_passes[1] = passOrientedSphereFit; + m_passes[2] = new ColorMap({1,1,1,1}); + m_passes[3] = new DisplayPoint({0,0,0,1}); inc_ref(); auto *window = new Window(this, "Utils"); - window->set_position(Vector2i(0, 0)); + window->set_position(Vector2i(1000, 0)); window->set_layout(new GroupLayout()); // IO @@ -73,10 +74,26 @@ Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ const int bordersize = 20; m_dataMgr->fitPointCloudToRange({tex_width-bordersize, tex_height-bordersize},{bordersize,bordersize}); }); + b = new Button(tools, "Flip x"); + b->set_callback([&] { + const int bordersize = 20; + for (auto& v : m_dataMgr->getPointContainer()){ + v.x() = tex_width - v.x(); + } + m_dataMgr->fitPointCloudToRange({tex_width-bordersize, tex_height-bordersize},{bordersize,bordersize}); + }); + b = new Button(tools, "Flip y"); + b->set_callback([&] { + const int bordersize = 20; + for (auto& v : m_dataMgr->getPointContainer()){ + v.y() = tex_height - v.y(); + } + m_dataMgr->fitPointCloudToRange({tex_width-bordersize, tex_height-bordersize},{bordersize,bordersize}); + }); } window = new Window(this, "Fitting Controls"); - window->set_position(Vector2i(0, 200)); + window->set_position(Vector2i(0, 0)); window->set_layout(new GroupLayout()); @@ -87,6 +104,7 @@ Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ "Sphere", "Oriented Sphere", "Unoriented Sphere"}); + combo->set_selected_index(3); combo->set_callback([this](int id){ switch (id) { case 0: m_passes[1] = passDFWithKdTree; break; @@ -110,7 +128,7 @@ Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ // dunno why, but sets colorpicker in range [0-255], but reads in [0-1] auto cp = new ColorPicker(pass1Widget, (dynamic_cast(m_passes[0]))->m_fillColor); cp->set_final_callback([this](const Color &c) { - dynamic_cast(m_passes[0])->m_fillColor = 255.f * c; + dynamic_cast(m_passes[0])->m_fillColor = c; renderPasses(); }); } @@ -164,34 +182,74 @@ Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ { pass3Widget = new nanogui::Widget(window); pass3Widget->set_layout(new GroupLayout()); - new nanogui::Label(pass3Widget, "Points Display", "sans-bold"); - new nanogui::Label(pass3Widget, "Color"); + new nanogui::Label(pass3Widget, "Colormap", "sans-bold"); + new nanogui::Label(pass3Widget, "0-iso color"); // dunno why, but sets colorpicker in range [0-255], but reads in [0-1] - auto cp = new ColorPicker(pass3Widget, (dynamic_cast(m_passes[2]))->m_pointColor); + auto cp = new ColorPicker(pass3Widget, (dynamic_cast(m_passes[2]))->m_isoColor); cp->set_final_callback([this](const Color &c) { - dynamic_cast(m_passes[2])->m_pointColor = 255.f * c; + dynamic_cast(m_passes[2])->m_isoColor = c; renderPasses(); }); + new nanogui::Label(pass3Widget, "Default color"); + cp = new ColorPicker(pass3Widget, (dynamic_cast(m_passes[2]))->m_defaultColor); + cp->set_final_callback([this](const Color &c) { + dynamic_cast(m_passes[2])->m_defaultColor = c; + renderPasses(); + }); + new nanogui::Label(pass3Widget, "Number of isolines"); + auto int_box = new IntBox(pass3Widget, dynamic_cast(m_passes[2])->m_isoQuantifyNumber); + int_box->set_editable(true); + int_box->set_spinnable(true); + int_box->set_min_value(1); + int_box->set_max_value(20); + int_box->set_value_increment(1); + int_box->set_callback([&](int value) { + dynamic_cast(m_passes[2])->m_isoQuantifyNumber = value; + renderPasses(); + }); + + new nanogui::Label(pass3Widget, "0-isoline width"); auto slider = new Slider(pass3Widget); - slider->set_value(dynamic_cast(m_passes[2])->m_halfSize); + slider->set_value(dynamic_cast(m_passes[2])->m_isoWidth); + slider->set_range({0.1,3.}); + slider->set_callback([&](float value) { + dynamic_cast(m_passes[2])->m_isoWidth = value; + renderPasses(); + }); + } + + // create pass 4 interface + { + pass4Widget = new nanogui::Widget(window); + pass4Widget->set_layout(new GroupLayout()); + new nanogui::Label(pass4Widget, "Points Display", "sans-bold"); + new nanogui::Label(pass4Widget, "Color"); + // dunno why, but sets colorpicker in range [0-255], but reads in [0-1] + auto cp = new ColorPicker(pass4Widget, (dynamic_cast(m_passes[3]))->m_pointColor); + cp->set_final_callback([this](const Color &c) { + dynamic_cast(m_passes[3])->m_pointColor = c; + renderPasses(); + }); + auto slider = new Slider(pass4Widget); + slider->set_value(dynamic_cast(m_passes[3])->m_halfSize); slider->set_range({1,20}); slider->set_callback([&](float value) { - dynamic_cast(m_passes[2])->m_halfSize = int(value); + dynamic_cast(m_passes[3])->m_halfSize = int(value); m_image_view->setSelectionThreshold(value); renderPasses(); }); } window = new Window(this, "Image"); - window->set_position(Vector2i(200, 0)); + window->set_position(Vector2i(210, 0)); window->set_size(Vector2i(768,768)); window->set_layout(new GroupLayout(3)); - m_textureBufferPing = new uint8_t [tex_width * tex_height * 4]; // use UInt8 RGBA textures - m_textureBufferPong = new uint8_t [tex_width * tex_height * 4]; // use UInt8 RGBA textures + m_textureBufferPing = new float [tex_width * tex_height * 4]; // use Float32 RGBA textures + m_textureBufferPong = new float [tex_width * tex_height * 4]; // use Float32 RGBA textures m_texture = new Texture( Texture::PixelFormat::RGBA, - Texture::ComponentFormat::UInt8, + Texture::ComponentFormat::Float32, {tex_width,tex_height}, Texture::InterpolationMode::Trilinear, Texture::InterpolationMode::Nearest, @@ -203,11 +261,10 @@ Screen(Vector2i(1024, 768), "PoncaPlot"), m_dataMgr(new DataManager()){ m_image_view->fitImage(); m_image_view->center(); - renderPasses(); // render twice to fill m_textureBufferPing and m_textureBufferPong - renderPasses(); + buildPassInterface(3); - // call perform_layout - buildPassInterface(0); + renderPasses(); + renderPasses(); // render twice to fill m_textureBufferPing and m_textureBufferPong } @@ -231,7 +288,7 @@ PoncaPlotApplication::draw(NVGcontext *ctx) { void PoncaPlotApplication::draw_contents() { if (m_needUpdate){ - m_texture->upload(m_computeInPing ? m_textureBufferPong : m_textureBufferPing); + m_texture->upload((const uint8_t*) (m_computeInPing ? m_textureBufferPong : m_textureBufferPing)); m_needUpdate = false; } Screen::draw_contents(); diff --git a/src/application.h b/src/application.h index 7c4b0d5..c95c87c 100644 --- a/src/application.h +++ b/src/application.h @@ -33,10 +33,10 @@ class PoncaPlotApplication : public nanogui::Screen { void renderPasses(); private: - uint8_t* m_textureBufferPing {nullptr}, * m_textureBufferPong {nullptr}; + float* m_textureBufferPing {nullptr}, * m_textureBufferPong {nullptr}; bool m_computeInPing{true}; nanogui::Texture* m_texture {nullptr}; - std::array m_passes{nullptr, nullptr, nullptr}; + std::array m_passes{nullptr, nullptr, nullptr, nullptr}; // fill, compute, colormap, point bool m_needUpdate{false}; DataManager *m_dataMgr{nullptr}; @@ -45,7 +45,7 @@ class PoncaPlotApplication : public nanogui::Screen { Widget* pass1Widget, *distanceFieldWidget, *genericFitWidget, //< parameters applicable to all fitting techniques *planeFitWidget, *sphereFitWidget, *orientedSphereFitWidget, *unorientedSphereFitWidget, - *pass3Widget; + *pass3Widget,*pass4Widget; DistanceFieldWithKdTree *passDFWithKdTree; PlaneFitField *passPlaneFit; SphereFitField *passSphereFit; diff --git a/src/drawingPass.h b/src/drawingPass.h index b8e9d49..2000cd5 100644 --- a/src/drawingPass.h +++ b/src/drawingPass.h @@ -8,14 +8,14 @@ /// Base class to rendering processes struct DrawingPass { - virtual void render(const DataManager::KdTree& points, uint8_t*buffer, int w, int h) = 0; + virtual void render(const DataManager::KdTree& points, float*buffer, int w, int h) = 0; virtual ~DrawingPass() = default; }; struct FillPass : public DrawingPass { - inline explicit FillPass(const nanogui::Vector4i &fillColor = {255,255,255,255}) + inline explicit FillPass(const nanogui::Vector4f &fillColor = {1,1,1,1}) : m_fillColor(fillColor) {} - void render(const DataManager::KdTree& /*points*/, uint8_t*buffer, int w, int h) override{ + void render(const DataManager::KdTree& /*points*/, float*buffer, int w, int h) override{ #pragma omp parallel for default(none) shared(buffer, w, h) for(auto j = 0; j 0.f) + { + c[0] = quantify(1.f - val / maxVal); + c[1] = 0; + c[2] = 0; + } + else + { + c[0] = 0; + c[1] = 0; + c[2] = quantify(1.f - (-val / maxVal)); + } + c[3] = 1; + } + + } + break; + default: + break; + } + b[0] = c.x(); + b[1] = c.y(); + b[2] = c.z(); + b[3] = c.w(); + } + } + + int m_isoQuantifyNumber {10}; + float m_isoWidth {0.8}; + nanogui::Vector4f m_isoColor; + nanogui::Vector4f m_defaultColor; + + enum FieldType: int { + SCALAR_FIELD = 10, + NO_FIELD + }; + + enum FieldValueType: bool { + VALUE_IS_VALID = true, + VALUE_IS_INVALID = false + }; +}; diff --git a/src/drawingPasses/distanceField.h b/src/drawingPasses/distanceField.h index cd7e049..d24b8b6 100644 --- a/src/drawingPasses/distanceField.h +++ b/src/drawingPasses/distanceField.h @@ -4,35 +4,45 @@ struct DistanceField : public DrawingPass { inline explicit DistanceField() : DrawingPass() {} - void render(const DataManager::KdTree& points, uint8_t*buffer, int w, int h) override { - if(points.point_data().empty()) return; + void render(const DataManager::KdTree& points, float*buffer, int w, int h) override { + if(points.point_data().empty()) + { + buffer[1] = ColorMap::NO_FIELD; + return; + } - const auto normFactor = float(std::max(w,h)); -#pragma omp parallel for collapse(2) default(none) shared(normFactor, points, buffer, w, h) + float maxVal = 0; +#pragma omp parallel for collapse(2) default(none) shared(points, buffer, w, h) reduction(max : maxVal) for (int j = 0; j < h; ++j ) { for (int i = 0; i < w; ++i) { auto *b = buffer + (i + j * w) * 4; - auto minDist = int(normFactor); //distance should necessarily be smaller + float minDist {float(w*h)}; //distance should necessarily be smaller for (const auto &p : points.point_data()) { int u(std::floor(p.pos().x())); int v(std::floor(p.pos().y())); - auto dist = int(std::sqrt((i-u)*(i-u) + (j-v)*(j-v))); + auto dist = float(std::sqrt((i-u)*(i-u) + (j-v)*(j-v))); minDist = std::min(dist, minDist); } - auto col = int(255. * minDist / normFactor); - b[0] = b[1] = b[2] = col; - b[3] = 255; + b[0] = minDist; + b[2] = ColorMap::VALUE_IS_VALID; + b[3] = ColorMap::SCALAR_FIELD; + if (std::abs(minDist)> maxVal) maxVal = std::abs(minDist); } } + buffer[1] = maxVal; } }; struct DistanceFieldWithKdTree : public DrawingPass { inline explicit DistanceFieldWithKdTree() : DrawingPass() {} - void render(const DataManager::KdTree& points, uint8_t*buffer, int w, int h) override{ - if(points.point_data().empty()) return; + void render(const DataManager::KdTree& points, float*buffer, int w, int h) override{ + if(points.point_data().empty()) + { + buffer[1] = ColorMap::NO_FIELD; + return; + } - const auto normFactor = float(std::max(w,h)); -#pragma omp parallel for collapse(2) default(none) shared(normFactor, points, buffer, w, h) + float maxVal = 0; +#pragma omp parallel for collapse(2) default(none) shared(points, buffer, w, h) reduction(max : maxVal) for (int j = 0; j < h; ++j ) { for (int i = 0; i < w; ++i) { auto *b = buffer + (i + j * w) * 4; @@ -41,11 +51,13 @@ struct DistanceFieldWithKdTree : public DrawingPass { if(res.begin()!=res.end()) { auto nei = points.point_data()[res.get()].pos(); float dist = (nei-query).norm(); - auto col = int (255. * dist / normFactor); - b[0] = b[1] = b[2] = col; - b[3] = 255; + b[0] = dist; + b[2] = ColorMap::VALUE_IS_VALID; + b[3] = ColorMap::SCALAR_FIELD; + if (std::abs(dist)> maxVal) maxVal = std::abs(dist); } } } + buffer[1] = maxVal; } }; diff --git a/src/drawingPasses/poncaFitField.h b/src/drawingPasses/poncaFitField.h index 2839c41..1c7806c 100644 --- a/src/drawingPasses/poncaFitField.h +++ b/src/drawingPasses/poncaFitField.h @@ -6,7 +6,7 @@ struct BaseFitField : public DrawingPass{ inline explicit BaseFitField() : DrawingPass() {} ~BaseFitField() override = default; - float m_scale {20.f}; + float m_scale {40.f}; int m_iter {1}; }; @@ -19,11 +19,11 @@ struct FitField : public BaseFitField { using WeightFunc = typename FitType::WeightFunction; - void render(const DataManager::KdTree& points, uint8_t*buffer, int w, int h) override{ + void render(const DataManager::KdTree& points, float*buffer, int w, int h) override{ if(points.point_data().empty()) return; - const auto normFactor = float(std::max(w,h)); -#pragma omp parallel for collapse(2) default(none) shared(normFactor, points, buffer, w, h) + float maxVal = 0; +#pragma omp parallel for collapse(2) default(none) shared(points, buffer, w, h) reduction(max : maxVal) for (int j = 0; j < h; ++j ) { for (int i = 0; i < w; ++i) { auto *b = buffer + (i + j * w) * 4; @@ -41,23 +41,19 @@ struct FitField : public BaseFitField { query = fit.project(query); } } - if (fit.isStable()){ + + if ( (b[2] = fit.isStable()) ){ float dist = fit.potential({i,j}); - if (dist * dist < 1.4) - b[0] = b[1] = b[2] = 255; - else { - auto col = int(255. * dist / m_scale); - if (dist > 0) - b[0] = b[1] = b[2] = col; - else { - b[0] = -col; - b[1] = b[2] = 0; - } - } - b[3] = 255; + if (std::abs(dist)> maxVal) maxVal = std::abs(dist); + + b[0] = dist; // set pixel value + b[3] = ColorMap::SCALAR_FIELD; // set field type } } } + // store data for colormap processing (see #ColorMap) + buffer[1] = maxVal; + buffer[3] = ColorMap::SCALAR_FIELD; } };