inline StkBox generateBoundingVolume< StkBox >(double x, double y, double z, double radius) { Point min_corner(x-radius,y-radius,z-radius); Point max_corner(x+radius,y+radius,z+radius); return StkBox(min_corner,max_corner); }
ccBBox ccSample::getMyOwnBB() { CCVector3 center = CCVector3::fromArray(getSample()->getPosition().data()); float s = 0.1; //10 cm CCVector3 scale_v(s, s, s); CCVector3 min_corner(center - scale_v); CCVector3 max_corner(center + scale_v); ccBBox box(min_corner, max_corner); return box; }
void BoundingVolume::transform(const BoundingVolume &in_volume, glm::mat4 matrix) { // Make sure the bounding volume itself is cleared before transformation reset(); glm::vec4 min_corner(in_volume.min_corner(), 1.0f); glm::vec4 max_corner(in_volume.max_corner(), 1.0f); glm::vec4 transformed_min_corner = matrix * min_corner; glm::vec4 transformed_max_corner = matrix * max_corner; glm::vec3 transformed_min(transformed_min_corner.x, transformed_min_corner.y, transformed_min_corner.z); glm::vec3 transformed_max(transformed_max_corner.x, transformed_max_corner.y, transformed_max_corner.z); // expand with the new corners expand(transformed_min); expand(transformed_max); }
WT_Result WT_PNG_Group4_Image::serialize(WT_File & file) const { WD_CHECK (file.dump_delayed_drawable()); WD_Assert(m_rows > 0); WD_Assert(m_columns > 0); WD_Assert(m_data); int colormap_size = 0; // Make sure we have a legal image WT_Integer32 parts_to_sync = // WT_Rendition::Color_Bit | // WT_Rendition::Color_Map_Bit | // WT_Rendition::Fill_Bit | WT_Rendition::Visibility_Bit | WT_Rendition::BlockRef_Bit | // WT_Rendition::Line_Weight_Bit | // WT_Rendition::Pen_Pattern_Bit | // WT_Rendition::Line_Pattern_Bit | // WT_Rendition::Line_Caps_Bit | // WT_Rendition::Line_Join_Bit | // WT_Rendition::Marker_Size_Bit | // WT_Rendition::Marker_Symbol_Bit | WT_Rendition::URL_Bit | WT_Rendition::Viewport_Bit | WT_Rendition::Layer_Bit | WT_Rendition::Object_Node_Bit; switch (m_format) { case Group4X_Mapped: WD_Assert(m_color_map); // There had better be a colormap attached if (!m_color_map) return WT_Result::File_Write_Error; WD_Assert(m_color_map->size() == 2); colormap_size = 1 + // For the colormap size byte m_color_map->size() * 4; // The colormap itself break; case Group4: case PNG: WD_Assert(!m_color_map); // There should not be any colormap attached break; default: return WT_Result::Internal_Error; } // switch WD_CHECK (file.desired_rendition().sync(file, parts_to_sync)); if (file.heuristics().apply_transform()) ((WT_PNG_Group4_Image *)this)->transform(file.heuristics().transform()); if (file.heuristics().allow_binary_data()) { ((WT_PNG_Group4_Image *)this)->relativize(file); WD_CHECK (file.write((WT_Byte) '{')); WD_CHECK (file.write((WT_Integer32) (sizeof(WT_Unsigned_Integer16) + // for the opcode sizeof(WT_Unsigned_Integer16) + // Num columns sizeof(WT_Unsigned_Integer16) + // Num rows sizeof(WT_Logical_Point) + // Lower left logical point sizeof(WT_Logical_Point) + // Upper right logical point sizeof(WT_Integer32) + // Image identifier colormap_size + // Space taken by the image's colormap, 0 in most cases sizeof(WT_Integer32) + // the data size m_data_size + // the image data sizeof(WT_Byte) // The closing "}" ))); WD_CHECK (file.write((WT_Unsigned_Integer16) format() )); WD_CHECK (file.write(columns())); WD_CHECK (file.write(rows())); WD_CHECK (file.write(1, &min_corner())); WD_CHECK (file.write(1, &max_corner())); WD_CHECK (file.write(identifier())); if (colormap_size) WD_CHECK(m_color_map->serialize_just_colors(file)); WD_CHECK (file.write(m_data_size)); // TODO: put in a switch here based on format so that color endianism is accounted for switch (m_format) { case Group4X_Mapped: case Group4: case PNG: WD_CHECK (file.write(m_data_size, m_data)); break; default: return WT_Result::Internal_Error; } // switch WD_CHECK (file.write((WT_Byte) '}')); } else { // Extended ASCII output WD_CHECK (file.write_geom_tab_level()); WD_CHECK (file.write("(Group4PNGImage ")); switch (format()) { case Group4X_Mapped: WD_CHECK (file.write_quoted_string("group 4X", WD_True)); break; case Group4: WD_CHECK (file.write_quoted_string("Group4", WD_True)); break; case PNG: WD_CHECK (file.write_quoted_string("PNG", WD_True)); break; default: return WT_Result::Internal_Error; } WD_CHECK (file.write((WT_Byte) ' ')); WD_CHECK (file.write_ascii(identifier())); WD_CHECK (file.write((WT_Byte) ' ')); WD_CHECK (file.write_ascii(columns())); WD_CHECK (file.write((WT_Byte) ',')); WD_CHECK (file.write_ascii(rows())); WD_CHECK (file.write((WT_Byte) ' ')); WD_CHECK (file.write_ascii(1, &min_corner())); WD_CHECK (file.write((WT_Byte) ' ')); WD_CHECK (file.write_ascii(1, &max_corner())); if ((colormap_size != 0) && (format() == Group4X_Mapped)) { WD_CHECK (file.write((WT_Byte) ' ')); WD_CHECK (file.write_ascii((WT_Unsigned_Integer16)colormap_size)); WD_CHECK (file.write((WT_Byte) ' ')); WD_CHECK(m_color_map->serialize(file)); } WD_CHECK (file.write(" (")); WD_CHECK (file.write_ascii(m_data_size)); WD_CHECK (file.write((WT_Byte) ' ')); // TODO: put in a switch here based on format so that color endianism is accounted for WD_CHECK (file.write_hex(m_data_size, m_data)); WD_CHECK (file.write("))")); } return WT_Result::Success; }
void DrawPolygon2(int index, RTREE& rtree2, std::vector<polygon>& polygons, int pmap[][HEIGHT]) { int xmin, ymin, xmax, ymax; box b; findCorner(xmin, ymin, xmax, ymax, b, index); std::vector<value> result; rtree2.query(bgi::intersects(b), std::back_inserter(result)); RTREE rtree(result.begin(), result.end()); // std::this_thread::sleep_for(std::chrono::seconds(index)); // std::cout << bg::wkt<box>(b) << std::endl; // std::cout<<"index = "<<index<<"min_corner = "<<xmin<<","<<ymin<<" max_corner = "<<xmax<<","<<ymax<<std::endl; // std::cout<<"polygon size: "<<polygons.size()<<std::endl; for (int i = xmin; i <= xmax; i++) for (int j = ymin; j <= ymax; j++) { if (pmap[i][j] == -1) { point sought = point(i, j); std::vector<value> result_n; for ( RTREE::const_query_iterator it = qbegin(rtree, bgi::nearest(sought, 100)) ; it != qend(rtree) ; ++it ) { int id = it->second; auto& poly = polygons[id]; auto box = it->first; if (!bg::within(sought, box)) break; if ( bg::within(sought, poly) ) { // std::cout<<"**********************\n"; // pmap[i][j] = id; point pmin = box.min_corner(); point pmax = box.max_corner(); int xmin2 = pmin.get<0>(); int ymin2 = pmin.get<1>(); int xmax2 = pmax.get<0>(); int ymax2 = pmax.get<1>(); for (int w = xmin2; w <= xmax2; w++) { for (int h = ymin2; h <= ymax2; h++) { if (w < xmin || h < ymin || w >= xmax || h >= ymax || pmap[w][h] >= 0) continue; if (bg::within(point(w, h), poly)) { pmap[w][h] = id; } } } break; } } } } // //random color // std::vector<int> colors; // int size = polygons.size(); // for ( int i = 0 ; i < size ; ++i ) // { // colors.push_back(i % 3 + 1); // } // //Draw pixel // // t1 = std::chrono::high_resolution_clock::now(); // cv::Mat mat(HEIGHT, WIDTH, CV_8UC4); // mat = cv::Scalar(0, 0, 0, 0); // for (int i = 0; i < WIDTH; i++) // for (int j = 0; j < HEIGHT; j++) // { // if (pmap[i][j] != -1) { // int c = colors[pmap[i][j]]; // auto color = c == 1 ? RED : c == 2 ? GREEN : BLUE; // line( mat, cv::Point(i, j), cv::Point(i, j), color, 2, 8); // } // } // line(mat, cv::Point(10, 10), cv::Point(251, 240), cv::Scalar(0, 0, 0, 255), 1, 8); // std::vector<int> compression_params; // compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION); // compression_params.push_back(9); // std::string filename = "DrawPolygon7_" + std::to_string(index) + ".png"; // imwrite(filename, mat, compression_params); }
/// \brief This function uses a pseudo-random technique to populate the /// forest with trees. This algorithm as the following essental properties: /// /// - It is repeatable. It can be repeated on the client and the server, /// and give identical results. /// /// - It is location independant. It gives the same results even if the /// forest is in a different place. /// /// - It is shape and size independant. A given area of the forest is /// the same even if the borders of the forest change. /// /// - It is localisable. It is possible to only partially populate the /// the forest, and still get the same results in that area. /// /// This function will have no effect if the area defining the forest remains /// uninitialised. Any previously generated contents are erased. /// For each instance a new seed is used to ensure it is repeatable, and /// height, displacement and orientation are calculated. void Forest::populate() { if (!m_area) { return; } auto bbox(m_area->bbox()); // Fill the plant store with plants. m_plants.clear(); WFMath::MTRand rng; int lx = std::lrint(bbox.min_corner().x()), ly = std::lrint(bbox.min_corner().y()), hx = std::lrint(bbox.max_corner().x()), hy = std::lrint(bbox.max_corner().y()); PlantSpecies::const_iterator I; PlantSpecies::const_iterator Iend = m_species.end(); for (int j = ly; j < hy; ++j) { for (int i = lx; i < hx; ++i) { if (!m_area->contains<float>(i, j)) { continue; } auto prob = m_randCache(i, j); I = m_species.begin(); for (; I != Iend; ++I) { Species const & species = *I; if (prob > species.m_probability) { prob -= species.m_probability; // Next species continue; } // std::cout << "Plant at [" << i << ", " << j << "]" // << std::endl << std::flush; //this is a bit of a hack rng.seed((int)(prob / I->m_probability * 123456)); Plant & plant = m_plants[i][j]; // plant.setHeight(rng() * plant_height_range + plant_min_height); plant.setDisplacement( (rng.rand<WFMath::CoordType>() - 0.5f) * species.m_deviation, (rng.rand<WFMath::CoordType>() - 0.5f) * species.m_deviation); plant.setOrientation(WFMath::Quaternion(2, rng.rand<WFMath::CoordType>() * 2 * WFMath::numeric_constants<WFMath::CoordType>::pi())); ParameterDict::const_iterator J = species.m_parameters.begin(); ParameterDict::const_iterator Jend = species.m_parameters.end(); for (; J != Jend; ++J) { plant.setParameter(J->first, rng.rand<WFMath::CoordType>() * J->second.range + J->second.min); } break; } } } }