pair<double, SplitSide> SAH(SplitPlane plane, AABB box, int left, int right, int planar) { pair<AABB, AABB> boxes = box.split(plane); double area = surfaceArea(box); double ratioLeft = surfaceArea(boxes.first) / area; double ratioRight = surfaceArea(boxes.second) / area; double costLeft = cost(ratioLeft, ratioRight, left + planar, right); double costRight = cost(ratioLeft, ratioRight, left, planar + right); if (costLeft < costRight) return make_pair(costLeft, LEFT); else return make_pair(costRight, RIGHT); }
float SAH(float plane, uint32_t axis, AABB *aabb, uint32_t left, uint32_t right, uint32_t *terminate) { AABB *aabbleft; AABB *aabbright; subdivideAABB(aabb, plane, axis, &aabbleft, &aabbright); float totalsurface = surfaceArea(aabb); float leftsurface = surfaceArea(aabbleft); float rightsurface = surfaceArea(aabbright); aabbFree(aabbleft); aabbFree(aabbright); *terminate = 0; return (left * leftsurface + right * rightsurface) / totalsurface; }
void CStarField::render(CVideoSurface *surface, CStarControlSub12 *sub12) { CSurfaceArea surfaceArea(surface); draw(&surfaceArea, sub12, &_sub5); // TODO }
void CStarCrosshairs::drawEntry(int index, CVideoSurface *surface, CStarField *starField, CStarMarkers *markers) { surface->lock(); CSurfaceArea surfaceArea(surface); drawAt(_entries[index], &surfaceArea); surface->unlock(); const CBaseStarEntry *starP = starField->getDataPtr(_entries[index]._index1); markers->addStar(starP); }
void Mesh::activate() { /* Create a discrete distribution for sampling triangles with respect to their surface area */ m_distr.clear(); m_distr.reserve(m_triangleCount); for (uint32_t i=0; i<m_triangleCount; ++i) m_distr.append(surfaceArea(i)); m_distr.normalize(); if (!m_bsdf) { /* If no material was assigned, instantiate a diffuse BRDF */ m_bsdf = static_cast<BSDF *>( NoriObjectFactory::createInstance("diffuse", PropertyList())); } }
bool CStarField::mouseButtonDown(CVideoSurface *surface, CStarCamera *camera, int flags, const Common::Point &pt) { if (_mode == MODE_STARFIELD) { CSurfaceArea surfaceArea(surface); return selectStar(&surfaceArea, camera, pt); } else { int starNum = _sub8.indexOf(pt); if (starNum >= 0) { _sub8.selectStar(starNum, surface, this, &_sub7); return true; } return false; } }
double InternalMassDefinition_Impl::getSurfaceArea(double floorArea, double numPeople) const { std::string method = designLevelCalculationMethod(); if (method == "SurfaceArea") { return surfaceArea().get(); } else if (method == "SurfaceArea/Area") { return surfaceAreaperSpaceFloorArea().get() * floorArea; } else if (method == "SurfaceArea/Person") { return surfaceAreaperPerson().get() * numPeople; } OS_ASSERT(false); return 0.0; }
void CStarField::render(CVideoSurface *surface, CStarCamera *camera) { CSurfaceArea surfaceArea(surface); draw(&surfaceArea, camera, &_starCloseup); if (_showCrosshairs) drawCrosshairs(&surfaceArea); _sub7.draw(&surfaceArea, camera, nullptr); _sub8.draw(&surfaceArea); if (_points2On) _points2.draw(&surfaceArea, camera); if (_points1On) _points1.draw(&surfaceArea, camera); fn4(&surfaceArea, camera); }
void Mesh::activate() { if (!m_bsdf) { /* If no material was assigned, instantiate a diffuse BRDF */ m_bsdf = static_cast<BSDF *>( NoriObjectFactory::createInstance("diffuse", PropertyList())); } //check if the mesh is an emitter if(isEmitter()){ m_dpdf = new DiscretePDF(m_F.cols()); //for every face set the surface area for (int i = 0; i < m_F.cols(); ++i) { float curArea = surfaceArea(i); m_dpdf->append(curArea); m_surfaceArea += curArea; } //normalize the pdf m_dpdf->normalize(); } }
double InternalMassDefinition_Impl::getSurfaceAreaPerPerson(double floorArea, double numPeople) const { std::string method = designLevelCalculationMethod(); if (method == "SurfaceArea") { if (equal(numPeople,0.0)) { LOG_AND_THROW("Calculation would require division by zero."); } return surfaceArea().get() / numPeople; } else if (method == "SurfaceArea/Area") { if (equal(numPeople,0.0)) { LOG_AND_THROW("Calculation would require division by zero."); } return surfaceAreaperSpaceFloorArea().get() * floorArea / numPeople; } else if (method == "SurfaceArea/Person") { return surfaceAreaperPerson().get(); } OS_ASSERT(false); return 0.0; }
void CStarCrosshairs::selectStar(int index, CVideoSurface *surface, CStarField *starField, CStarMarkers *markers) { if (_entryIndex >= 0) { // There are existing selected stars already if (_entryIndex == _matchIndex) { // All the stars selected so far have been matched. Only allow // a selection addition if not all three stars have been found if (!isSolved()) { // Don't allow the most recent match or the one before // it to be re-selected (while they are locked/matched) if (_positions[index] != _entries[_entryIndex]) { if (_entryIndex == 1) { // 2 stars are matched if (_positions[index] == _entries[_entryIndex - 1]) return; } surface->lock(); // Draw crosshairs around the selected star CSurfaceArea surfaceArea(surface); drawStar(index, &surfaceArea); surface->unlock(); // Copy the star into the list of selected ones ++_entryIndex; CStarPosition &newP = _entries[_entryIndex]; newP = _positions[index]; // Set up a marker in the main starfield for that same star const CBaseStarEntry *starP = starField->getDataPtr(newP._index1); markers->addStar(starP); } } } else if (_entryIndex == _matchIndex + 1) { // There is a most recently selected star that has not yet been matched. // So we allow the user to reselect it to remove the selection, or shift // the selection to some other star if (_positions[index] == _entries[_entryIndex]) { // Player has selected the most recent star // Remove the crosshairs for the previously selected star surface->lock(); CSurfaceArea surfaceArea(surface); eraseCurrent(&surfaceArea); surface->unlock(); // Decrement number of selections --_entryIndex; // Call the markers addStar method, which will remove the existing marker const CBaseStarEntry *starP = starField->getDataPtr(_positions[index]._index1); markers->addStar(starP); } else { // Player has selected some other star other than the most recent // Remove/Add it if it is not one of the other star(s) already matched // Check that it is not a previously star and don't remove it if it is for (int i = 0; i < _entryIndex; ++i) { if (_positions[index] == _entries[i]) return; } // Erase the prior selection and draw the new one surface->lock(); CSurfaceArea surfaceArea(surface); eraseCurrent(&surfaceArea); drawStar(index, &surfaceArea); surface->unlock(); // Remove the old selection from the starfield markers const CBaseStarEntry *starP; starP = starField->getDataPtr(_entries[_entryIndex]._index1); markers->addStar(starP); // Add the new selection to the markers list starP = starField->getDataPtr(_positions[index]._index1); markers->addStar(starP); // Copy the newly selected star's details into our selections list CStarPosition &newP = _entries[_entryIndex]; newP = _positions[index]; } } } else { // Very first star being selected // Draw crosshairs around the selected star surface->lock(); CSurfaceArea surfaceArea(surface); drawStar(index, &surfaceArea); surface->unlock(); // Copy the star into the list of selected ones ++_entryIndex; const CStarPosition &srcPos = _positions[index]; CStarPosition &destPos = _entries[_entryIndex]; destPos = srcPos; // Set up a marker in the main starfield for that same star const CBaseStarEntry *starP = starField->getDataPtr(destPos._index1); markers->addStar(starP); } }
KDNode* KDNode::limitedBuild(vector<Triangle*>& triangles, int depth, int depthLimit) { KDNode* node = new KDNode(); node->left = NULL; node->right = NULL; #ifdef _DEBUG printf("level %d, %d triangles\n", depth, triangles.size()); #endif //Calculate the bounding box bool firstTriangle = true; AABB boundingBox; for (auto it : triangles) { if (firstTriangle) { firstTriangle = false; //Use the first triangle's bounding box as base since 0,0,0->0,0,0 still //keeps the end at 0,0,0 even if all triangles have negative coordinates. //Are we guaranteed to have > 0 triangles? boundingBox = it->getBoundingBox(); } boundingBox.addBox(it->getBoundingBox()); } //Leaf node: fewer than 4 triangles or reached sufficient depth if (triangles.size() < 4 || depth >= depthLimit) { node->triangles = triangles; return node; } pair<pair<SplitPlane, SplitSide>, double> split = node->findPlane(triangles, boundingBox); //If can't get a better SAH, by splitting, make a leaf if (split.second >= surfaceArea(boundingBox) * triangles.size()) { node->triangles = triangles; return node; } double splitCoordinate = split.first.first.getCoordinate(); vector<Triangle*> left; vector<Triangle*> right; for (auto t : triangles) { double triangleStart = t->getBoundingBox().getStartpoint()[split.first.first.getAxis()]; double triangleEnd = t->getBoundingBox().getEndpoint()[split.first.first.getAxis()]; if (triangleStart == triangleEnd && triangleStart == splitCoordinate) if (split.first.second == LEFT) left.push_back(t); else right.push_back(t); else { if (triangleStart < splitCoordinate) left.push_back(t); if (triangleEnd > splitCoordinate) right.push_back(t); } } node->left = limitedBuild(left, depth + 1, depthLimit); node->right = limitedBuild(right, depth + 1, depthLimit); node->plane = split.first.first; return node; }
void CStarField::fn6(CVideoSurface *surface, CStarCamera *camera) { CSurfaceArea surfaceArea(surface); _sub8.fn1(this, &surfaceArea, camera); }