Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

estimation.cpp

Go to the documentation of this file.
00001 #include <CGAL/IO/Qt_widget.h>
00002 #include "estimation.hpp"
00003 #include "jet.hpp"
00004 
00005 using namespace Arak;
00006 
00007 PointSetColorEstimator::PointSetColorEstimator(ArakMarkovChain& chain,
00008                  const Arak::Util::PropertyMap& props) : chain(chain) {
00009   using namespace Arak::Util;
00010   int n = 1;
00011   if (hasp(props, "arak.mcmc.estimation.grid_size")) {
00012     parse(getp(props, "arak.mcmc.estimation.grid_size"), n);
00013     assert(n > 0);
00014   }
00015   Geometry::Rectangle r = chain.getState().boundary();
00016   Geometry::Kernel::FT width = r.xmax() - r.xmin();
00017   Geometry::Kernel::FT height = r.ymax() - r.ymin();
00018   double aspect_ratio = CGAL::to_double(width) / CGAL::to_double(height);
00019   int rows = std::max(1, int(sqrt(double(n) / aspect_ratio)));
00020   int cols = n / rows;
00021   index = new QueryPointIndex(r, rows, cols);
00022   index->addListeners(*this);
00023   chain.getState().addQueryPoints(*index);
00024 }
00025 
00026 void PointSetColorEstimator::visualize(CGAL::Qt_widget& widget) const {
00027   using namespace CGAL;
00028   widget << PointSize(6) << PointStyle(BOX);
00029   typedef std::list<PointColorEstimator*>::const_iterator Iterator;
00030   for (Iterator it = estimators.begin(); it != estimators.end(); it++) {
00031     const PointColorEstimator* estimator = *it;
00032     // Gamma-correct the intensities for an accurate visualization.
00033     double intensity = 1.0 - estimator->estimate();
00034     const double gamma = 1.0 / 0.45;
00035     double gc_intensity = pow(intensity, gamma);
00036     int gray = int(round(255.0 * gc_intensity));
00037     CGAL::Color c(gray, gray, gray);
00038     widget << c << estimator->point;
00039   }
00040 }
00041 
00042 GridColorEstimator::GridColorEstimator(ArakMarkovChain& chain,
00043                const Arak::Util::PropertyMap& props)
00044   : chain(chain) {
00045   using namespace Arak::Util;
00046   int n = 1;
00047   if (hasp(props, "arak.mcmc.estimation.grid_size")) {
00048     parse(getp(props, "arak.mcmc.estimation.grid_size"), n);
00049     assert(n > 0);
00050   }
00051   Geometry::Rectangle r = chain.getState().boundary();
00052   Geometry::Kernel::FT width = r.xmax() - r.xmin();
00053   Geometry::Kernel::FT height = r.ymax() - r.ymin();
00054   double aspect_ratio = CGAL::to_double(width) / CGAL::to_double(height);
00055   int rows = std::max(1, int(sqrt(double(n) / aspect_ratio)));
00056   int cols = n / rows;
00057   grid = new EstimatorGrid(r, rows, cols);
00058   for (int i = 0; i < rows; i++)
00059     for (int j = 0; j < cols; j++) {
00060       EstimatorGrid::Cell& cell = grid->getCell(i, j);
00061       Geometry::Point p = CGAL::midpoint(cell[0], cell[2]);
00062       Color color = chain.getState().color(p);
00063       PointColorEstimator* pce = new PointColorEstimator(chain, p, color);
00064       estimators.push_back(pce);
00065       cell.add(pce);
00066     }
00067   chain.getState().addListener(*this);
00068 }
00069 
00070 void GridColorEstimator::recolored(const Geometry::Point& a,
00071            const Geometry::Point& b,
00072            const Geometry::Point& c) {
00073   Geometry::Triangle t(a, b, c);
00074   EstimatorGrid::TriangleCellIterator it(*grid, t), end;
00075   do {
00076     PointColorEstimator* pce = *(it->getItemList().begin());
00077     if (t.has_on_bounded_side(pce->point))
00078       pce->recolor(opposite(pce->color));
00079   } while (++it != end);
00080 }
00081 
00082 void GridColorEstimator::visualize(CGAL::Qt_widget& widget) const {
00083   using namespace CGAL;
00084   for (int i = grid->numRows() - 1; i >= 0; i--) {
00085     for (int j = 0; j < grid->numCols(); j++) {
00086       const EstimatorGrid::Cell& cell = grid->getCell(i, j);
00087       const PointColorEstimator* pce = *(cell.getItemList().begin());
00088       int n = int(double(Arak::jet_size - 1) * pce->estimate());    
00089       const CGAL::Color& c = Arak::jet_colors[n];
00090       // Cannot avoid plotting the cell boundary!
00091       widget.setFilled(true);
00092       widget.setLineWidth(0);
00093       widget.setPointSize(0);
00094       widget << c << CGAL::FillColor(c) << cell; 
00095     }
00096   }
00097 }
00098 
00099 

Generated on Wed May 25 14:39:16 2005 for Arak by doxygen 1.3.6