hkpShape* vHavokCachedShape::LoadTerrainSectorShape(const VTerrainSector *pSector) { #ifndef SUPPORTS_HKT return HK_NULL; #else VASSERT(pSector != NULL); const VTerrainSector::VPhysicsType_e ePhysicsType = pSector->GetPhysicsType(); const bool bHasHoles = pSector->HasHoles(); // First get filename by specifying extension (hmap) to be able to retrieve the absolute path. // Afterwards remove extension. char szFilename[FS_MAX_PATH]; pSector->m_Config.GetSectorFilename(szFilename, pSector->m_iIndexX, pSector->m_iIndexY, "hmap", true); VFileAccessManager::NativePathResult sectorNativeResult; if (VFileAccessManager::GetInstance()->MakePathNative(szFilename, sectorNativeResult, VFileSystemAccessMode::READ, VFileSystemElementType::FILE) != HKV_SUCCESS) { VASSERT_MSG(FALSE, "vHavokShapeFactory::GetHktDependencies: Failed to determine the native path to the sector hmap; the file may not exist!"); return NULL; } VFileHelper::GetFilenameNoExt(szFilename, sectorNativeResult.m_sNativePath); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(szFilename); GetTerrainSectorShapePath(szCachedShapeName, ePhysicsType, bHasHoles); if (ePhysicsType == VTerrainSector::VPHYSICSTYPE_APPROXIMATE) return LoadShape(szCachedShapeName, hkvSampledHeightFieldShapeClass); else if (bHasHoles) return LoadShape(szCachedShapeName, hkvTriSampledHeightFieldBvTreeShapeClass); else return LoadShape(szCachedShapeName, hkpTriSampledHeightFieldBvTreeShapeClass); #endif }
bool VolumetricFog::onAdd() { if (!Parent::onAdd()) return false; if (!VFRTM->IsInitialized()) { Con::errorf("No VolumetricFogRTManager present!!"); return false; } resetWorldBox(); mShapeLoaded = LoadShape(); setRenderTransform(mObjToWorld); addToScene(); ColBox.set(getTransform(), (mObjBox.getExtents() * getScale() * COLBOX_SCALE)); mObjSize = mWorldBox.getGreatestDiagonalLength(); mObjScale = getScale(); mTexTiles = mAbs(mTexTiles); mSpeed.set(mSpeed1.x, mSpeed1.y, mSpeed2.x, mSpeed2.y); mInvScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z)); if (isClientObject()) { InitTexture(); return setupRenderer(); } VFRTM->IncFogObjects(); return true; }
bool VolumetricFog::onAdd() { if (!Parent::onAdd()) return false; if (!VFRTM->IsInitialized()) { Con::errorf("No VolumetricFogRTManager present!!"); return false; } resetWorldBox(); mShapeLoaded = LoadShape(); setRenderTransform(mObjToWorld); addToScene(); ColBox.set(getTransform(), (mObjBox.getExtents() * getScale() * COLBOX_SCALE)); mObjSize = mWorldBox.getGreatestDiagonalLength(); mObjScale = getScale(); mTexTiles = mAbs(mTexTiles); mSpeed.set(mSpeed1.x, mSpeed1.y, mSpeed2.x, mSpeed2.y); mInvScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z)); if (isClientObject()) { conn = GameConnection::getConnectionToServer(); if (!conn) { Con::errorf("VolumetricFog::onAdd - No Serverconnection"); return false; } glowFX = static_cast<PostEffect*>(Sim::findObject("VolFogGlowPostFx")); mOldLightRayStrength = Con::getFloatVariable("$LightRayPostFX::brightScalar",1.0f); GuiCanvas* cv = dynamic_cast<GuiCanvas*>(Sim::findObject("Canvas")); if (cv == NULL) { Con::errorf("VolumetricFog::onAdd - Canvas not found!!"); return false; } mPlatformWindow = cv->getPlatformWindow(); VolumetricFogRTManager::getVolumetricFogRTMResizeSignal().notify(this, &VolumetricFog::handleResize); GuiCanvas::getCanvasSizeChangeSignal().notify(this, &VolumetricFog::handleCanvasResize); InitTexture(); return setupRenderer(); } VFRTM->IncFogObjects(); return true; }
bool ObjectRenderer::Load(const pXmlTree tree){ if(tree==NULL) return false; gLOG.SetCurrentEntry("ObjectRenderer"); gLOG.Append("Setting up BBoxShape for object: %s",tree->GetData().c_str()); gLOG.SetDeltaIndent(2); pXmlTree bbox = tree->Find("BBoxShape"); if(bbox!=NULL){ pXmlTreeList tmpList = bbox->GetSubTrees(); for(unsigned int i=0;i<tmpList->size();i++){ pShapeStruct shape = LoadShape(tmpList->at(i)); if(shape!=NULL) mBBoxShapes.push_back(shape); } }else{ gLOG.SetDeltaIndent(2); gLOG.Append("Warning: No <BBoxShape> found"); gLOG.SetDeltaIndent(-2); } gLOG.SetDeltaIndent(-2); gLOG.Append("Setting up GfxShape for object: %s",tree->GetData().c_str()); gLOG.SetDeltaIndent(2); pXmlTree gfx = tree->Find("GfxShape"); if(gfx!=NULL){ pXmlTreeList tmpList = gfx->GetSubTrees(); for(unsigned int i=0;i<tmpList->size();i++){ pShapeStruct shape = LoadShape(tmpList->at(i)); if(shape!=NULL) mShapes.push_back(shape); } }else{ gLOG.SetDeltaIndent(2); gLOG.Append("Warning: No <GfxShape> found"); gLOG.SetDeltaIndent(-2); } gLOG.SetDeltaIndent(-2); return true; }
void TopographyFile::LoadAll() { // Iterate through the shapefile entries const ShapeList **current = &first; auto it = shapes.begin(); for (int i = 0; i < file.numshapes; ++i, ++it) { if (it->shape == nullptr) // shape isn't cached yet -> cache the shape it->shape = LoadShape(&file, center, i, label_field); // update list pointer *current = it; current = &it->next; } // end of list marker *current = nullptr; ++serial; }
hkvConvexVerticesShape* vHavokCachedShape::LoadConvexShape(VBaseMesh *pMesh, const hkvVec3& vScale, bool bShrinkToFit) { #ifndef SUPPORTS_HKT return HK_NULL; #else VASSERT(pMesh != NULL); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(pMesh->GetFilename()); GetConvexShapePath(szCachedShapeName, vScale, bShrinkToFit); hkvConvexVerticesShape *pShape = (hkvConvexVerticesShape*)LoadShape(szCachedShapeName, hkvConvexVerticesShapeClass); if ((Vision::Editor.IsInEditor() || IsHktUpToDateCheckingEnabled()) && pShape!=HK_NULL) { if (!IsHktUpToDate(pMesh, pShape, hkvConvexVerticesShapeClass)) return HK_NULL; } return pShape; #endif }
void wxJigsawEditorMainFrame::LoadPalettes() { m_Palettes.DeleteContents(true); for(wxJigsawShapeCategoryList::Node * node = m_Config->GetCategories().GetFirst(); node; node = node->GetNext()) { wxJigsawShapeCategory * category = node->GetData(); if(!category) continue; wxJigsawPalette * palette = new wxJigsawPalette; palette->SetPaletteName(category->GetCategoryName()); palette->SetColours(category->GetColourData()); for(size_t i = 0; i < category->GetShapeFileNames().Count(); i++) { wxJigsawShape * shape = LoadShape(category->GetShapeFileNames()[i]); if(!shape) continue; if(category->GetOverwriteShapeColor()) shape->SetColour(palette->GetColours().GetColour()); palette->GetShapes().Append(shape); } m_Palettes.Append(palette); } }
hkvBvCompressedMeshShape* vHavokCachedShape::LoadMeshShape(VBaseMesh *pMesh, const hkvVec3& vScale, VisStaticMeshInstance_cl::VisCollisionBehavior_e eCollisionBehavior, VisWeldingType_e eWeldingType) { #ifndef SUPPORTS_HKT return HK_NULL; #else VASSERT(pMesh != NULL); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(pMesh->GetFilename()); GetMeshShapePath(szCachedShapeName, vScale, eCollisionBehavior, eWeldingType); hkvBvCompressedMeshShape *pShape = (hkvBvCompressedMeshShape*)LoadShape(szCachedShapeName, hkvBvCompressedMeshShapeClass); if ((Vision::Editor.IsInEditor() || IsHktUpToDateCheckingEnabled()) && pShape!=HK_NULL) { if (!IsHktUpToDate(pMesh, pShape, hkvBvCompressedMeshShapeClass)) return HK_NULL; } return pShape; #endif }
bool TopographyFile::Update(const WindowProjection &map_projection) { if (IsEmpty()) return false; if (map_projection.GetMapScale() > scale_threshold) /* not visible, don't update cache now */ return false; const GeoBounds screenRect = map_projection.GetScreenBounds(); if (cache_bounds.IsValid() && cache_bounds.IsInside(screenRect)) /* the cache is still fresh */ return false; cache_bounds = screenRect.Scale(2); rectObj deg_bounds = ConvertRect(cache_bounds); // Test which shapes are inside the given bounds and save the // status to file.status switch (msShapefileWhichShapes(&file, dir, deg_bounds, 0)) { case MS_FAILURE: ClearCache(); return false; case MS_DONE: /* screen is outside of map bounds */ return false; case MS_SUCCESS: break; } assert(file.status != nullptr); // Iterate through the shapefile entries const ShapeList **current = &first; auto it = shapes.begin(); for (int i = 0; i < file.numshapes; ++i, ++it) { if (!msGetBit(file.status, i)) { // If the shape is outside the bounds // delete the shape from the cache if (it->shape != nullptr) { assert(*current == it); /* remove from linked list (protected) */ { const ScopeLock lock(mutex); *current = it->next; ++serial; } /* now it's unreachable, and we can delete the XShape without holding a lock */ delete it->shape; it->shape = nullptr; } } else { // is inside the bounds if (it->shape == nullptr) { assert(*current != it); // shape isn't cached yet -> cache the shape it->shape = LoadShape(&file, center, i, label_field); it->next = *current; /* insert into linked list (protected) */ { const ScopeLock lock(mutex); *current = it; ++serial; } } current = &it->next; } } // end of list marker assert(*current == nullptr); return true; }
int main() { const int triangleCount = 111; const int trianglePoints = 68; const Vec2i resolution(169, 167); std::string meanShape = "Data/Mean_Shape.txt"; std::string currentShape = "Data/Current_Shape.txt"; std::string triangles = "Data/Triangles.txt"; std::string textureBase = "Data/Texture_Base.txt"; std::string imageName = "Data/inputImage.png"; cv::Mat inputImage = cv::imread(imageName, CV_LOAD_IMAGE_GRAYSCALE); if(!inputImage.data) { std::cerr << "Could not open or find the image" << std::endl; std::exit(EXIT_FAILURE); } std::vector<Vec2i> trianglePointsList[triangleCount]; LoadTextureBase(textureBase, resolution, trianglePointsList); // load points rounded to nearest int Vec2i* meanPoints = new Vec2i[trianglePoints]; LoadShape(meanShape, meanPoints); Vec2i* currentPoints = new Vec2i[trianglePoints]; LoadShape(currentShape, currentPoints); // load points as floats Vec2f* meanPointsf = new Vec2f[trianglePoints]; LoadShapef(meanShape, meanPointsf); Vec2f* currentPointsf = new Vec2f[trianglePoints]; LoadShapef(currentShape, currentPointsf); Index* indices = new Index[triangleCount]; LoadIndices(triangles, indices); cv::Mat outImage = cv::Mat::zeros(resolution.y, resolution.x, inputImage.type()); clock_t timeC; int loops = 10000; timeC = clock(); for(int y = 0; y < loops; ++y) { WarpImage(meanPoints, currentPoints, indices, triangleCount, trianglePointsList, inputImage, outImage); } timeC = clock() - timeC; std::cout << "WarpImage time to do " << loops << " loops: " << timeC * 1000 / CLOCKS_PER_SEC << " milliseconds." << std::endl; cv::Mat outImagef = cv::Mat::zeros(resolution.y, resolution.x, inputImage.type()); timeC = clock(); for(int y = 0; y < loops; ++y) { WarpImagef(meanPointsf, currentPointsf, indices, triangleCount, trianglePointsList, inputImage, outImagef); } timeC = clock() - timeC; std::cout << "WarpImagef time to do " << loops << " loops: " << timeC * 1000 / CLOCKS_PER_SEC << " milliseconds." << std::endl; cv::namedWindow("WarpImage image", CV_WINDOW_AUTOSIZE ); cv::imshow("WarpImage image", outImage); cv::namedWindow("WarpImage imagef", CV_WINDOW_AUTOSIZE ); cv::imshow("WarpImage imagef", outImagef); cv::waitKey(0); delete[] indices; delete[] currentPointsf; delete[] meanPointsf; delete[] currentPoints; delete[] meanPoints; return 0; }