map<Stroka, double> MatterStable::TwoPhaseBoundary::MakeBndPnt() { VecCl V, D, P; int SpinIndMin, SpinIndMax; map<Stroka, double> ret; ret["T"] = T; ret["DSr_T"] = 0; ret["DSl_T"] = 0; ret["Dr_T"] = 0; ret["Dl_T"] = 0; ret["P_T"] = 0; ret["E_T"] = 0; ret["dPdT_T"] = 0; if(!SetDP(V, D, P, SpinIndMin, SpinIndMax)) return ret; ret["T"] = T; TwoPhaseBoundary *OldPtr = TwoPhaseBoundaryStaticPtr; PrepareStatic(P, V); double PT_From, PT_To; FindMinMax(V, SpinIndMax, ZeroFunc_Spl_Vmin, PT_From, 1); ret["DSr_T"] = 1 / ZeroFunc_Spl_Vmin; FindMinMax(V, SpinIndMin, ZeroFunc_Spl_Vmax, PT_To, 0); ret["DSl_T"] = 1 / ZeroFunc_Spl_Vmax; IntegralFunc_Negative = 0; double PT_est = IntegralFunc_PV_Int_Static((ZeroFunc_Spl_Vmin + ZeroFunc_Spl_Vmax) * 0.5); Fzero( ZeroFunc_PV_Int_Static, max<double>(PT_From, sqrt(MathZer)), max<double>(PT_To, sqrt(MathZer)), PT_est, Mis * 0.1, Mis * 0.1, 100); //Fzero(ZeroFunc_PV_Int_Static, PT_From, PT_To, PT_est, Mis*0.1, Mis*0.1, 100); ZeroFunc_PV_Int_Static(PT_est); //ret["P_T"] = PT_est; ret["Dl_T"] = 1 / ZeroFunc_SplRes_Bmax; ret["Dr_T"] = 1 / ZeroFunc_SplRes_Bmin; ret["P_T"] = 0.5 * (Mat->Pressure(ret["Dr_T"], T) + Mat->Pressure(ret["Dl_T"], T)); ret["E_T"] = Mat->Energy(ret["Dr_T"], T); double E0 = ret["E_T"]; //,P0=Mat->Pressure(ret["Dr_T"],T); double E1 = Mat->Energy(ret["Dl_T"], T); ret["dPdT_T"] = -(E0 - E1) / (1 / ret["Dr_T"] - 1 / ret["Dl_T"]); ret["Pr_T"] = Mat->Pressure(ret["Dr_T"], T); ret["Pl_T"] = Mat->Pressure(ret["Dl_T"], T); ret["PSr_T"] = Mat->Pressure(ret["DSr_T"], T); ret["PSl_T"] = Mat->Pressure(ret["DSl_T"], T); //if (fabs(ret["Pr_T"]-ret["Pl_T"])>Mis) cout<<" BinodalBndPres l "<<ret["PSl_T"]<<" r "<<ret["PSr_T"]<<"\n"; TwoPhaseBoundaryStaticPtr = OldPtr; return ret; }
void TChart::CalcOriginScale() { FindMinMax(); if(BottomAxis!=NULL) if(BottomAxis->GetMinMax().IsNull()) BottomAxis->SetInterval(BottomAxis->GetMinMax()); if(BottomAxis!=NULL) if(BottomAxis->GetInterval().IsNull()) BottomAxis->SetInterval(BottomAxis->GetMinMax()); if(LeftAxis!=NULL) if(LeftAxis->GetMinMax().IsNull()) LeftAxis->SetInterval(LeftAxis->GetMinMax()); if(LeftAxis!=NULL) if(LeftAxis->GetInterval().IsNull()) LeftAxis->SetInterval(LeftAxis->GetMinMax()); if(BottomAxis!=NULL && LeftAxis!=NULL) { TChartInterval xx=BottomAxis->GetInterval(); TChartInterval yy=LeftAxis->GetInterval(); CRect area; area=Frame->DrawArea; FrameRender.Set(xx,yy,area); area.OffsetRect(-area.TopLeft()); SeriesRender.Set(xx,yy,area); } }
bool TSData::fromTextFile(QString fileName, TSData **ts) { int count, dim; float **Data; int ok = ReadInputData(&Data, &count, &dim, fileName.toLatin1().data()); if (!ok) { return false; } float **minMax = FindMinMax(Data, count, dim); TRAININGSET generated_ts = WriteData2CB(Data, count, dim, minMax, 1); /* TODO: we're throwing away the minmax file, that isn't nice but shouldn't matter if we don't want to do conversion back to txt */ *ts = new TSData(&generated_ts); fvDeleteSet(Data, count); fvDeleteSet(minMax, dim); FreeCodebook(&generated_ts); return true; }
LRESULT TChart::OnChartShowAll( WPARAM wParam, LPARAM lParam ) { FindMinMax(); BottomAxis->SetInterval(BottomAxis->GetMinMax()); LeftAxis->SetInterval(LeftAxis->GetMinMax()); UpdateNow(REPAINT_DEFAULT); return 0; }
S3DModel* CS3OParser::Load(std::string name) { PUSH_CODE_MODE; ENTER_SYNCED; CFileHandler file(name); if(!file.FileExists()){ POP_CODE_MODE; throw content_error("File not found: "+name); } unsigned char* fileBuf=SAFE_NEW unsigned char[file.FileSize()]; file.Read(fileBuf, file.FileSize()); S3OHeader header; memcpy(&header,fileBuf,sizeof(header)); header.swap(); S3DModel *model = SAFE_NEW S3DModel; model->type=MODELTYPE_S3O; model->numobjects=0; model->name=name; model->tex1=(char*)&fileBuf[header.texture1]; model->tex2=(char*)&fileBuf[header.texture2]; texturehandlerS3O->LoadS3OTexture(model); SS3OPiece* object=LoadPiece(fileBuf,header.rootPiece,model); object->type=MODELTYPE_S3O; FindMinMax(object); model->rootobject=object; model->radius = header.radius; model->height = header.height; model->relMidPos.x=header.midx; model->relMidPos.y=header.midy; model->relMidPos.z=header.midz; if(model->relMidPos.y<1) model->relMidPos.y=1; model->maxx=object->maxx; model->maxy=object->maxy; model->maxz=object->maxz; model->minx=object->minx; model->miny=object->miny; model->minz=object->minz; delete[] fileBuf; POP_CODE_MODE; return model; }
void CS3OParser::FindMinMax(SS3O *object) { std::vector<SS3O*>::iterator si; for(si=object->childs.begin();si!=object->childs.end();++si){ FindMinMax(*si); } float maxx=-1000,maxy=-1000,maxz=-1000; float minx=10000,miny=10000,minz=10000; std::vector<SS3OVertex>::iterator vi; for(vi=object->vertices.begin();vi!=object->vertices.end();++vi){ maxx=std::max(maxx,vi->pos.x); maxy=std::max(maxy,vi->pos.y); maxz=std::max(maxz,vi->pos.z); minx=std::min(minx,vi->pos.x); miny=std::min(miny,vi->pos.y); minz=std::min(minz,vi->pos.z); } for(si=object->childs.begin();si!=object->childs.end();++si){ maxx=std::max(maxx,(*si)->offset.x+(*si)->maxx); maxy=std::max(maxy,(*si)->offset.y+(*si)->maxy); maxz=std::max(maxz,(*si)->offset.z+(*si)->maxz); minx=std::min(minx,(*si)->offset.x+(*si)->minx); miny=std::min(miny,(*si)->offset.y+(*si)->miny); minz=std::min(minz,(*si)->offset.z+(*si)->minz); } object->maxx=maxx; object->maxy=maxy; object->maxz=maxz; object->minx=minx; object->miny=miny; object->minz=minz; }
S3DOModel* CS3OParser::LoadS3O(std::string name,float scale,int side) { GML_STDMUTEX_LOCK(model); // LoadS3O if(name.find(".")==std::string::npos) name+=".s3o"; StringToLowerInPlace(name); std::map<std::string,S3DOModel*>::iterator ui; if((ui=units.find(name))!=units.end()){ return ui->second; } PUSH_CODE_MODE; ENTER_SYNCED; CFileHandler file(name); if(!file.FileExists()){ POP_CODE_MODE; throw content_error("File not found: "+name); } unsigned char* fileBuf=SAFE_NEW unsigned char[file.FileSize()]; file.Read(fileBuf, file.FileSize()); S3OHeader header; memcpy(&header,fileBuf,sizeof(header)); header.swap(); S3DOModel *model = SAFE_NEW S3DOModel; model->numobjects=0; SS3O* object=LoadPiece(fileBuf,header.rootPiece,model); model->rootobjects3o=object; model->rootobject3do=0; object->isEmpty=true; model->name=name; model->tex1=(char*)&fileBuf[header.texture1]; model->tex2=(char*)&fileBuf[header.texture2]; texturehandler->LoadS3OTexture(model); FindMinMax(object); units[name]=model; CreateLists(object); // this is a hack to make aircrafts less likely to collide and get hit by nontracking weapons // note: does not apply anymore, unit <--> projectile coldet no longer depends on model->radius model->radius = header.radius * scale; model->height = header.height; model->relMidPos.x=header.midx; model->relMidPos.y=header.midy; model->relMidPos.z=header.midz; if(model->relMidPos.y<1) model->relMidPos.y=1; // logOutput.Print("%s has height %f",name,model->height); fartextureHandler->CreateFarTexture(model); model->maxx=model->rootobjects3o->maxx; model->maxy=model->rootobjects3o->maxy; model->maxz=model->rootobjects3o->maxz; model->minx=model->rootobjects3o->minx; model->miny=model->rootobjects3o->miny; model->minz=model->rootobjects3o->minz; delete[] fileBuf; POP_CODE_MODE; return model; }
CModel* CS3OParser::Load3DO(string name,float scale,int side) { if(name.find(".")==string::npos) name+=".s3o"; StringToLowerInPlace(name); map<string,CModel*>::iterator ui; if((ui=units.find(name))!=units.end()){ return ui->second; } PUSH_CODE_MODE; ENTER_SYNCED; CFileHandler file(name); if(!file.FileExists()){ POP_CODE_MODE; throw content_error("File not found: "+name); } unsigned char* fileBuf=new unsigned char[file.FileSize()]; file.Read(fileBuf, file.FileSize()); S3OHeader header; memcpy(&header,fileBuf,sizeof(header)); CModel *model = new CModel; model->numobjects=0; SS3O* object=LoadPiece(fileBuf,header.rootPiece,model,-1); model->rootobjects3o=object; model->rootobject3do=0; object->isEmpty=true; model->name=name; model->textureType=texturehandler->LoadS3OTexture((char*)&fileBuf[header.texture1],(char*)&fileBuf[header.texture2]); FindMinMax(object); units[name]=model; CreateLists(object); model->radius = header.radius*scale; //this is a hack to make aircrafts less likely to collide and get hit by nontracking weapons model->height = header.height; model->relMidPos.x=header.midx; model->relMidPos.y=header.midy; model->relMidPos.z=header.midz; if(model->relMidPos.y<1) model->relMidPos.y=1; // info->AddLine("%s has height %f",name,model->height); fartextureHandler->CreateFarTexture(model); model->maxx=model->rootobjects3o->maxx; model->maxy=model->rootobjects3o->maxy; model->maxz=model->rootobjects3o->maxz; model->minx=model->rootobjects3o->minx; model->miny=model->rootobjects3o->miny; model->minz=model->rootobjects3o->minz; delete[] fileBuf; POP_CODE_MODE; return model; }
bool CN3PMesh::Load(HANDLE hFile) { CN3BaseFileAccess::Load(hFile); DWORD dwNum; ReadFile(hFile, &m_iNumCollapses, sizeof(m_iNumCollapses), &dwNum, NULL); ReadFile(hFile, &m_iTotalIndexChanges, sizeof(m_iTotalIndexChanges), &dwNum, NULL); ReadFile(hFile, &m_iMaxNumVertices, sizeof(int), &dwNum, NULL); ReadFile(hFile, &m_iMaxNumIndices , sizeof(int), &dwNum, NULL); ReadFile(hFile, &m_iMinNumVertices, sizeof(int), &dwNum, NULL); ReadFile(hFile, &m_iMinNumIndices , sizeof(int), &dwNum, NULL); HRESULT hr = Create(m_iMaxNumVertices, m_iMaxNumIndices); __ASSERT(SUCCEEDED(hr), "Failed to create progressive mesh"); #ifdef _USE_VERTEXBUFFER if (m_iMaxNumVertices>0) { // HRESULT hr = m_lpD3DDev->CreateVertexBuffer(m_iMaxNumVertices*sizeof(__VertexT1), // D3DUSAGE_DYNAMIC, FVF_VNT1, D3DPOOL_MANAGED, &m_pVB); // if (FAILED(hr)) return hr; BYTE* pByte; hr = m_pVB->Lock(0, 0, &pByte, 0); if (FAILED(hr)) return false; ReadFile(hFile, pByte, m_iMaxNumVertices*sizeof(__VertexT1), &dwNum, NULL); m_pVB->Unlock(); } if (m_iMaxNumIndices>0) { // HRESULT hr = m_lpD3DDev->CreateIndexBuffer(m_iMaxNumIndices*sizeof(WORD), // D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIB); // if (FAILED(hr)) return hr; BYTE* pByte; hr = m_pIB->Lock(0, 0, &pByte, 0); if (FAILED(hr)) return false; ReadFile(hFile, pByte, m_iMaxNumIndices*sizeof(WORD), &dwNum, NULL); m_pIB->Unlock(); } #else if (m_iMaxNumVertices>0) { // m_pVertices = new __VertexT1[m_iMaxNumVertices]; ReadFile(hFile, m_pVertices, m_iMaxNumVertices*sizeof(__VertexT1), &dwNum, NULL); } if (m_iMaxNumIndices>0) { // m_pIndices = new WORD[m_iMaxNumIndices]; ReadFile(hFile, m_pIndices, m_iMaxNumIndices*sizeof(WORD), &dwNum, NULL); } #endif if (m_iNumCollapses>0) { m_pCollapses = new __EdgeCollapse[m_iNumCollapses+1]; // +1을 한 이유 : PMeshInstance::SplitOne() 함수에서 부득이하게 포인터가 경계선을 가르키게 해야 하는 경우가 있어서. ReadFile(hFile, m_pCollapses, m_iNumCollapses*sizeof(__EdgeCollapse), &dwNum, NULL); ZeroMemory(m_pCollapses + m_iNumCollapses, sizeof(__EdgeCollapse)); // 위의 +1을 한이유와 같음. 만약을 대비해 마지막 데이타를 초기화 해둠 bool bFixed = false; for(int i = 0; i < m_iNumCollapses; i++) { if(m_pCollapses[i].iIndexChanges < 0) { m_pCollapses[i].iIndexChanges = 0; bFixed = true; } } #ifdef _DEBUG if(bFixed) ::MessageBox(GetActiveWindow(), "잘못된 Progressive Mesh 수정", m_szName.c_str(), MB_OK); #endif } if (m_iTotalIndexChanges>0) { m_pAllIndexChanges = new int[m_iTotalIndexChanges]; ReadFile(hFile, m_pAllIndexChanges, m_iTotalIndexChanges*sizeof(int), &dwNum, NULL); } __ASSERT(m_pLODCtrlValues == NULL && m_iLODCtrlValueCount == 0, "Invalid Level of detail control value"); ReadFile(hFile, &m_iLODCtrlValueCount, sizeof(m_iLODCtrlValueCount), &dwNum, NULL); if (m_iLODCtrlValueCount>0) { m_pLODCtrlValues = new __LODCtrlValue[m_iLODCtrlValueCount]; ReadFile(hFile, m_pLODCtrlValues, m_iLODCtrlValueCount*sizeof(__LODCtrlValue), &dwNum, NULL); } FindMinMax(); return true; }