int main(int argc, char * argv[]) { FILE * fp; const char * inFilename = infile; const char * outFilename = "weights.bin"; int i, err = 0; int append = 0; // only write one time step if (argc > 1) { inFilename = argv[1]; } // header information const int numParams = 7; int params[numParams]; int nParams; int nxp, nyp, nfp, numNeurons; int minVal, maxVal; int numInPatches; fp = pv_open_binary(inFilename, &nParams, &nxp, &nyp, &nfp); pv_read_binary_params(fp, numParams, params); minVal = params[4]; maxVal = params[5]; numInPatches = params[6]; //int numItems = nxp*nyp*nfp; PVPatch ** inPatches = PV::HyPerConn::createPatches(numInPatches, nxp, nyp, nfp); PVPatch ** wPatches = createPatches(numNeurons, nxp, nyp, nfp); err = pv_read_patches(fp, nfp, minVal, maxVal, inPatches, numInPatches); for (i = 0; i < numNeurons; i += nfp) { for (int f = 0; f < nfp; f++) { wPatches[i+f]->data = inPatches[f]->data; } } pv_close_binary(fp); // output the weight patches err = pv_write_patches(outFilename, append, nxp, nyp, nfp, minVal, maxVal, numNeurons, wPatches); PV::HyPerConn::deletePatches(numNeurons, inPatches); deletePatches(numNeurons, wPatches); return err; }
bool TerrainPager::Init() { assert(NULL != pDevice && "Direct 3D Device not set"); geometryStream = StreamReader::Create("map"); assert(NULL != geometryStream); // No data to read just quit. if (utilizeTextures) { texturesStream = StreamReader::Create("textures"); assert(NULL != texturesStream); // No data to read just quit. } pPatchResolution = PatchResolution::Create(resolution); if (NULL == pPatchResolution) return false; pPatchVerticesMapping = PatchVerticesMapping::Create(pPatchResolution); if (NULL == pPatchVerticesMapping) return false; pPatchFacesIndexer = PatchFacesIndexer::Create(pPatchResolution); if (NULL == pPatchFacesIndexer) return false; createVertexDeclarations(); // Now create device objects // determine vertex buffer size. int vrtsPerPatchRow = pPatchResolution->GetValue() + 1; int vrtsPerPatch = vrtsPerPatchRow * vrtsPerPatchRow; int vrtsInAllPatches = vrtsPerPatch * nbAllocatedPatches; HRESULT hr; // create texture uv vertex buffer V(pDevice->CreateVertexBuffer( vrtsPerPatch * 2 * sizeof(float), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &vbTexUV, NULL)); // fill the uv vertex buffer. struct UV { float u, v; }; UV *texUV; float step = 1.0f / pPatchResolution->GetValue(); int index; V(vbTexUV->Lock(0, 0, (void**)&texUV, 0)); for(int i = 0; i <= pPatchResolution->GetValue(); ++i) for (int j = 0; j <= pPatchResolution->GetValue(); ++j) { index = (*pPatchVerticesMapping)(i, j); texUV[index].u = j * step; texUV[index].v = i * step; } V(vbTexUV->Unlock()); // create geomtery vertex buffer. V(pDevice->CreateVertexBuffer( vrtsInAllPatches * sizeof(TerrainVertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &pVB, NULL)); if (false == createPatches(vrtsPerPatch)) return false; if (false == createIndices()) return false; jobManager = new JobManager(pPatchResolution->GetLevelsCount(), utilizeTextures); return true; }