/* * Transfer the values from patch centered at psiHatQ to patch centered at psiHatP in * mat according to maskMat. */ void transferPatch(const cv::Point& psiHatQ, const cv::Point& psiHatP, cv::Mat& mat, const cv::Mat& maskMat) { assert(maskMat.type() == CV_8U); assert(mat.size() == maskMat.size()); assert(RADIUS <= psiHatQ.x && psiHatQ.x < mat.cols-RADIUS && RADIUS <= psiHatQ.y && psiHatQ.y < mat.rows-RADIUS); assert(RADIUS <= psiHatP.x && psiHatP.x < mat.cols-RADIUS && RADIUS <= psiHatP.y && psiHatP.y < mat.rows-RADIUS); // copy contents of psiHatQ to psiHatP with mask getPatch(mat, psiHatQ).copyTo(getPatch(mat, psiHatP), getPatch(maskMat, psiHatP)); }
void NNClassifier::train(const TYPE_TRAIN_DATA_SET &trainDataSet) { for(auto &trainData : trainDataSet) { Mat patch = getPatch(trainData.first); if(trainData.second == CLASS_POS || trainData.second == CLASS_NEG) { if(update(patch, trainData.second)) { addToNewSamples(patch, trainData.second); } } } for(auto &trainData : trainDataSet) { if(trainData.second == CLASS_TEST_NEG) { int dummy; float Sr = calcSr(trainData.first, dummy); if(Sr > thPos) { thPos = Sr; stringstream info; info << "Increase threshold of positive class to " << thPos; outputInfo("NN", info.str()); } } } }
vector<Mat> SelfLearningMeasurementModel::getFeatureVectors(const vector<shared_ptr<ClassifiedPatch>>& patches) { vector<Mat> trainingExamples; trainingExamples.reserve(patches.size()); for (auto patch = make_indirect_iterator(patches.cbegin()); patch != make_indirect_iterator(patches.cend()); ++patch) trainingExamples.push_back(patch->getPatch()->getData()); return trainingExamples; }
void LLSurface::setOriginGlobal(const LLVector3d &origin_global) { LLVector3d new_origin_global; mOriginGlobal = origin_global; LLSurfacePatch *patchp; S32 i, j; // Need to update the southwest corners of the patches for (j=0; j<mPatchesPerEdge; j++) { for (i=0; i<mPatchesPerEdge; i++) { patchp = getPatch(i, j); new_origin_global = patchp->getOriginGlobal(); new_origin_global.mdV[0] = mOriginGlobal.mdV[0] + i * mMetersPerGrid * mGridsPerPatchEdge; new_origin_global.mdV[1] = mOriginGlobal.mdV[1] + j * mMetersPerGrid * mGridsPerPatchEdge; patchp->setOriginGlobal(new_origin_global); } } // Hack! if (mWaterObjp.notNull() && mWaterObjp->mDrawable.notNull()) { const F64 x = origin_global.mdV[VX] + 128.0; const F64 y = origin_global.mdV[VY] + 128.0; const F64 z = mWaterObjp->getPositionGlobal().mdV[VZ]; LLVector3d water_origin_global(x, y, z); mWaterObjp->setPositionGlobal(water_origin_global); } }
void InstanceProcessor::loadPatch(std::string const& name, std::string const& path) { suspendProcessing(true); if(isSuspended()) { { releaseDsp(); m_patch = pd::Patch(*this, name, path); pd::Patch patch(getPatch()); if(patch.isValid()) { m_patch_tie = pd::Tie(std::to_string(patch.getDollarZero()) + "-playhead"); } else { m_patch_tie = pd::Tie(); sendConsoleError("Camomile can't find the patch : " + name); } } parametersChanged(); prepareDsp(getTotalNumInputChannels(), getTotalNumOutputChannels(), AudioProcessor::getSampleRate(), getBlockSize()); pd::PatchManager::notifyListeners(); } suspendProcessing(false); }
TEST_P(TestASMu2D, ConstrainEdge) { SIM2D sim(1); ASMu2D* pch = getPatch(sim); ASSERT_TRUE(pch != nullptr); pch->constrainEdge(GetParam().edgeIdx, false, 1, 1, 1); std::vector<int> glbNodes; pch->getBoundaryNodes(GetParam().edge, glbNodes, 1, 1, 0); for (int& it : glbNodes) ASSERT_TRUE(pch->findMPC(it, 1) != nullptr); }
void InstanceProcessor::parametersChanged() { size_t index = 0; lock(); for(size_t i = 0; i < m_parameters.size(); i++) { m_parameters[i] = pd::Parameter(); } unlock(); pd::Patch patch(getPatch()); if(patch.isValid()) { std::vector<pd::Gui> guis(patch.getGuis()); for(auto const& gui : guis) { if(gui.isParameter()) { bool ok = true; for(size_t i = 0; i < m_parameters.size() && m_parameters[i].isValid(); i++) { if(gui.getName() == m_parameters[i].getName()) { sendConsoleError("Warning in patch " + patch.getName() + ": " + gui.getName() + " parameter is duplicated !"); ok = false; break; } else if(gui.getReceiveTie() == m_parameters[i].getTie()) { sendConsoleError("Warning in patch " + patch.getName() + ": " + gui.getName() + " parameter shares the same receive symbol with another parameter !"); ok = false; break; } } if(ok) { m_parameters[index] = pd::Parameter(gui); index++; } } } } updateHostDisplay(); for(size_t i = 0; i < m_parameters.size(); i++) { if(m_parameters[i].isValid()) { setParameterNotifyingHost(i, m_parameters[i].getValueNormalized()); } } }
TEST_P(TestASMu2D, ConstrainEdgeOpen) { SIM2D sim(1); ASMu2D* pch = getPatch(sim); ASSERT_TRUE(pch != nullptr); pch->constrainEdge(GetParam().edgeIdx, true, 1, 1, 1); std::vector<int> glbNodes; pch->getBoundaryNodes(GetParam().edge, glbNodes, 1, 1, 0); int crn = pch->getCorner(GetParam().c1[0], GetParam().c1[1], 1); ASSERT_TRUE(pch->findMPC(crn, 1) == nullptr); glbNodes.erase(std::find(glbNodes.begin(), glbNodes.end(), crn)); crn = pch->getCorner(GetParam().c2[0], GetParam().c2[1], 1); ASSERT_TRUE(pch->findMPC(crn, 1) == nullptr); glbNodes.erase(std::find(glbNodes.begin(), glbNodes.end(), crn)); for (int& it : glbNodes) ASSERT_TRUE(pch->findMPC(it, 1) != nullptr); }
void InstanceProcessor::getStateInformation(MemoryBlock& destData) { juce::XmlElement xml(String("CamomileSettings")); pd::Patch patch(getPatch()); if(patch.isValid()) { xml.setAttribute(String("name"), patch.getName()); xml.setAttribute(String("path"), patch.getPath()); } XmlElement* params = xml.createNewChildElement("params"); for(size_t i = 0; i < m_parameters.size(); i++) { if(m_parameters[i].isValid()) { params->setAttribute(String(m_parameters[i].getName()), double(m_parameters[i].getValueNormalized())); } } copyXmlToBinary(xml, destData); }
void NNClassifier::getS(const cv::Mat &img, float &Sp, float &Sn, float &Sr, float &Sc, int &maxSPIdx) { Mat patch = getPatch(img); float maxSp = 0, maxSpHalf = 0.; int halfSize = ((int)pPatches.size() + 1) / 2; int count = 0; maxSPIdx = -1; for(auto &pPatch : pPatches) { float S = (calcNCC(pPatch, patch) + 1) * 0.5; if(S > maxSp) { maxSp = S; maxSPIdx = count; } if(++count <= halfSize) maxSpHalf = max(maxSpHalf, S); } float maxSn = 0; for(auto &nPatch : nPatches) { float S = (calcNCC(nPatch, patch) + 1) * 0.5; maxSn = max(maxSn, S); } float dSpHalf = 1 - maxSpHalf; float dSp = 1 - maxSp; float dSn = 1 - maxSn; Sr = dSn / (dSp + dSn); Sc = dSn / (dSpHalf + dSn); Sn = maxSn; Sp = maxSp; }
void LLSurface::connectNeighbor(LLSurface *neighborp, U32 direction) { S32 i; LLSurfacePatch *patchp, *neighbor_patchp; // <FS:CR> Aurora Sim S32 neighborPatchesPerEdge = neighborp->mPatchesPerEdge; // </FS:CR> Aurora Sim mNeighbors[direction] = neighborp; neighborp->mNeighbors[gDirOpposite[direction]] = this; // <FS:CR> Aurora Sim S32 ppe[2]; S32 own_offset[2] = {0, 0}; S32 neighbor_offset[2] = {0, 0}; U32 own_xpos, own_ypos, neighbor_xpos, neighbor_ypos; ppe[0] = (mPatchesPerEdge < neighborPatchesPerEdge) ? mPatchesPerEdge : neighborPatchesPerEdge; // used for x ppe[1] = ppe[0]; // used for y from_region_handle(mRegionp->getHandle(), &own_xpos, &own_ypos); from_region_handle(neighborp->getRegion()->getHandle(), &neighbor_xpos, &neighbor_ypos); if(own_ypos >= neighbor_ypos) { neighbor_offset[1] = (own_ypos - neighbor_ypos) / mGridsPerPatchEdge; ppe[1] = llmin(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[1]); } else { own_offset[1] = (neighbor_ypos - own_ypos) / mGridsPerPatchEdge; ppe[1] = llmin(mPatchesPerEdge-own_offset[1], neighborPatchesPerEdge); } if(own_xpos >= neighbor_xpos) { neighbor_offset[0] = (own_xpos - neighbor_xpos) / mGridsPerPatchEdge; ppe[0] = llmin(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[0]); } else { own_offset[0] = (neighbor_xpos - own_xpos) / mGridsPerPatchEdge; ppe[0] = llmin(mPatchesPerEdge-own_offset[0], neighborPatchesPerEdge); } // <FS:CR> Aurora Sim // Connect patches if (NORTHEAST == direction) { patchp = getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1); // <FS:CR> Aurora Sim //neighbor_patchp = neighborp->getPatch(0, 0); neighbor_patchp = neighborp->getPatch(neighbor_offset[0], neighbor_offset[1]); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateNorthEdge(); // Only update one of north or east. patchp->dirtyZ(); } else if (NORTHWEST == direction) { // <FS:CR> Aurora Sim S32 off = mPatchesPerEdge + neighbor_offset[1] - own_offset[1]; // </FS:CR> Aurora Sim patchp = getPatch(0, mPatchesPerEdge - 1); // <FS:CR> Aurora Sim //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, 0); neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, off); //neighborPatchesPerEdge - 1 if (!neighbor_patchp) { mNeighbors[direction] = NULL; return; } // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); } else if (SOUTHWEST == direction) { patchp = getPatch(0, 0); // <FS:CR> Aurora Sim //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, neighbor_offset[1] - 1); if (!neighbor_patchp) { mNeighbors[direction] = NULL; return; } // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); // <FS:CR> Aurora Sim //neighbor_patchp->updateNorthEdge(); // Only update one of north or east. neighbor_patchp->updateEastEdge(); // Only update one of north or east. // </FS:CR> Aurora Sim neighbor_patchp->dirtyZ(); } else if (SOUTHEAST == direction) { // <FS:CR> Aurora Sim S32 off = mPatchesPerEdge + neighbor_offset[0] - own_offset[0]; // </FS:CR> Aurora Sim patchp = getPatch(mPatchesPerEdge - 1, 0); // <FS:CR> Aurora Sim //neighbor_patchp = neighborp->getPatch(0, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(off, neighbor_offset[1] - 1); //0 if (!neighbor_patchp) { mNeighbors[direction] = NULL; return; } // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); } else if (EAST == direction) { // Do east/west connections, first // <FS:CR> Aurora Sim //for (i = 0; i < (S32)mPatchesPerEdge; i++) for (i = 0; i < ppe[1]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(mPatchesPerEdge - 1, i); //neighbor_patchp = neighborp->getPatch(0, i); patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(0, i + neighbor_offset[1]); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateEastEdge(); patchp->dirtyZ(); } // Now do northeast/southwest connections // <FS:CR> Aurora Sim //for (i = 0; i < (S32)mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[1] - 1; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(mPatchesPerEdge - 1, i); //neighbor_patchp = neighborp->getPatch(0, i+1); patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(0, i+1 + neighbor_offset[1]); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, NORTHEAST); neighbor_patchp->connectNeighbor(patchp, SOUTHWEST); } // Now do southeast/northwest connections // <FS:CR> Aurora Sim //for (i = 1; i < (S32)mPatchesPerEdge; i++) for (i = 1; i < ppe[1]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(mPatchesPerEdge - 1, i); //neighbor_patchp = neighborp->getPatch(0, i-1); patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(0, i-1 + neighbor_offset[1]); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, SOUTHEAST); neighbor_patchp->connectNeighbor(patchp, NORTHWEST); } } else if (NORTH == direction) { // Do north/south connections, first // <FS:CR> Aurora Sim //for (i = 0; i < (S32)mPatchesPerEdge; i++) for (i = 0; i < ppe[0]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(i, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(i, 0); patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], 0); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateNorthEdge(); patchp->dirtyZ(); } // Do northeast/southwest connections // <FS:CR> Aurora Sim //for (i = 0; i < (S32)mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[0] - 1; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(i, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(i+1, 0); patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i+1 + neighbor_offset[0], 0); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, NORTHEAST); neighbor_patchp->connectNeighbor(patchp, SOUTHWEST); } // Do southeast/northwest connections // <FS:CR> Aurora Sim //for (i = 1; i < (S32)mPatchesPerEdge; i++) for (i = 1; i < ppe[0]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(i, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(i-1, 0); patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i-1 + neighbor_offset[0], 0); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, NORTHWEST); neighbor_patchp->connectNeighbor(patchp, SOUTHEAST); } } else if (WEST == direction) { // Do east/west connections, first // <FS:CR> Aurora Sim //for (i = 0; i < mPatchesPerEdge; i++) for (i = 0; i < ppe[1]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(0, i); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i); patchp = getPatch(0, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + neighbor_offset[1]); if (!neighbor_patchp) continue; // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateEastEdge(); neighbor_patchp->dirtyZ(); } // Now do northeast/southwest connections // <FS:CR> Aurora Sim //for (i = 1; i < mPatchesPerEdge; i++) for (i = 1; i < ppe[1]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(0, i); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i - 1); patchp = getPatch(0, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i - 1 + neighbor_offset[1]); if (!neighbor_patchp) continue; // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, SOUTHWEST); neighbor_patchp->connectNeighbor(patchp, NORTHEAST); } // Now do northwest/southeast connections // <FS:CR> Aurora Sim //for (i = 0; i < mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[1] - 1; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(0, i); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i + 1); patchp = getPatch(0, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + 1 + neighbor_offset[1]); if (!neighbor_patchp) continue; // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, NORTHWEST); neighbor_patchp->connectNeighbor(patchp, SOUTHEAST); } } else if (SOUTH == direction) { // Do north/south connections, first // <FS:CR> Aurora Sim //for (i = 0; i < mPatchesPerEdge; i++) for (i = 0; i < ppe[0]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(i, 0); //neighbor_patchp = neighborp->getPatch(i, mPatchesPerEdge - 1); patchp = getPatch(i + own_offset[0], 0); neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], neighborPatchesPerEdge - 1); if (!neighbor_patchp) continue; // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateNorthEdge(); neighbor_patchp->dirtyZ(); } // Now do northeast/southwest connections // <FS:CR> Aurora Sim //for (i = 1; i < mPatchesPerEdge; i++) for (i = 1; i < ppe[0]; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(i, 0); //neighbor_patchp = neighborp->getPatch(i - 1, mPatchesPerEdge - 1); patchp = getPatch(i + own_offset[0], 0); neighbor_patchp = neighborp->getPatch(i - 1 + neighbor_offset[0], neighborPatchesPerEdge - 1); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, SOUTHWEST); neighbor_patchp->connectNeighbor(patchp, NORTHEAST); } // Now do northeast/southwest connections // <FS:CR> Aurora Sim //for (i = 0; i < mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[0] - 1; i++) // </FS:CR> Aurora Sim { // <FS:CR> Aurora Sim //patchp = getPatch(i, 0); //neighbor_patchp = neighborp->getPatch(i + 1, mPatchesPerEdge - 1); patchp = getPatch(i + own_offset[0], 0); neighbor_patchp = neighborp->getPatch(i + 1 + neighbor_offset[0], neighborPatchesPerEdge - 1); // </FS:CR> Aurora Sim patchp->connectNeighbor(neighbor_patchp, SOUTHEAST); neighbor_patchp->connectNeighbor(patchp, NORTHWEST); } } }
void LLSurface::connectNeighbor(LLSurface *neighborp, U32 direction) { if (gNoRender) { return; } S32 i; LLSurfacePatch *patchp, *neighbor_patchp; S32 neighborPatchesPerEdge = neighborp->mPatchesPerEdge; mNeighbors[direction] = neighborp; neighborp->mNeighbors[gDirOpposite[direction]] = this; S32 ppe[2]; S32 own_offset[2] = {0, 0}; S32 neighbor_offset[2] = {0, 0}; U32 own_xpos, own_ypos, neighbor_xpos, neighbor_ypos; #undef min //'Cause Windows is /brilliant/ ppe[0] = std::min(mPatchesPerEdge,neighborPatchesPerEdge); // used for x ppe[1] = std::min(mPatchesPerEdge,neighborPatchesPerEdge); // used for y from_region_handle(mRegionp->getHandle(), &own_xpos, &own_ypos); from_region_handle(neighborp->getRegion()->getHandle(), &neighbor_xpos, &neighbor_ypos); if(own_ypos >= neighbor_ypos) { neighbor_offset[1] = (own_ypos - neighbor_ypos) / mGridsPerPatchEdge; ppe[1] = std::min(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[1]); } else { own_offset[1] = (neighbor_ypos - own_ypos) / mGridsPerPatchEdge; ppe[1] = std::min(mPatchesPerEdge-own_offset[1], neighborPatchesPerEdge); } if(own_xpos >= neighbor_xpos) { neighbor_offset[0] = (own_xpos - neighbor_xpos) / mGridsPerPatchEdge; ppe[0] = std::min(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[0]); } else { own_offset[0] = (neighbor_xpos - own_xpos) / mGridsPerPatchEdge; ppe[0] = std::min(mPatchesPerEdge-own_offset[0], neighborPatchesPerEdge); } // Connect patches if (NORTHEAST == direction) { patchp = getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(0, 0); neighbor_patchp = neighborp->getPatch(neighbor_offset[0], neighbor_offset[1]); //0 patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateNorthEdge(); // Only update one of north or east. patchp->dirtyZ(); } else if (NORTHWEST == direction) { S32 off = mPatchesPerEdge + neighbor_offset[1] - own_offset[1]; patchp = getPatch(0, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, 0); neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, off); //neighborPatchesPerEdge - 1 patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); } else if (SOUTHWEST == direction) { patchp = getPatch(0, 0); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, neighbor_offset[1] - 1); //neighborPatchesPerEdge - 1 patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); //neighbor_patchp->updateNorthEdge(); // Only update one of north or east. neighbor_patchp->updateEastEdge(); // Only update one of north or east. neighbor_patchp->dirtyZ(); } else if (SOUTHEAST == direction) { S32 off = mPatchesPerEdge + neighbor_offset[0] - own_offset[0]; patchp = getPatch(mPatchesPerEdge - 1, 0); //neighbor_patchp = neighborp->getPatch(0, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(off, neighbor_offset[1] - 1); //0 patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); } else if (EAST == direction) { // Do east/west connections, first //for (i = 0; i < (S32)mPatchesPerEdge; i++) for (i = 0; i < ppe[1]; i++) { //patchp = getPatch(mPatchesPerEdge - 1, i); //neighbor_patchp = neighborp->getPatch(0, i); patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(0, i + neighbor_offset[1]); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateEastEdge(); patchp->dirtyZ(); } // Now do northeast/southwest connections //for (i = 0; i < (S32)mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[1] - 1; i++) { //patchp = getPatch(mPatchesPerEdge - 1, i); //neighbor_patchp = neighborp->getPatch(0, i+1); patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(0, i+1 + neighbor_offset[1]); patchp->connectNeighbor(neighbor_patchp, NORTHEAST); neighbor_patchp->connectNeighbor(patchp, SOUTHWEST); } // Now do southeast/northwest connections //for (i = 1; i < (S32)mPatchesPerEdge; i++) for (i = 1; i < ppe[1]; i++) { //patchp = getPatch(mPatchesPerEdge - 1, i); //neighbor_patchp = neighborp->getPatch(0, i-1); patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(0, i-1 + neighbor_offset[1]); patchp->connectNeighbor(neighbor_patchp, SOUTHEAST); neighbor_patchp->connectNeighbor(patchp, NORTHWEST); } } else if (NORTH == direction) { // Do north/south connections, first //for (i = 0; i < (S32)mPatchesPerEdge; i++) for (i = 0; i < ppe[0]; i++) { //patchp = getPatch(i, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(i, 0); patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], 0); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateNorthEdge(); patchp->dirtyZ(); } // Do northeast/southwest connections //for (i = 0; i < (S32)mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[0] - 1; i++) { //patchp = getPatch(i, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(i+1, 0); patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i+1 + neighbor_offset[0], 0); patchp->connectNeighbor(neighbor_patchp, NORTHEAST); neighbor_patchp->connectNeighbor(patchp, SOUTHWEST); } // Do southeast/northwest connections //for (i = 1; i < (S32)mPatchesPerEdge; i++) for (i = 1; i < ppe[0]; i++) { //patchp = getPatch(i, mPatchesPerEdge - 1); //neighbor_patchp = neighborp->getPatch(i-1, 0); patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i-1 + neighbor_offset[0], 0); patchp->connectNeighbor(neighbor_patchp, NORTHWEST); neighbor_patchp->connectNeighbor(patchp, SOUTHEAST); } } else if (WEST == direction) { // Do east/west connections, first //for (i = 0; i < mPatchesPerEdge; i++) for (i = 0; i < ppe[1]; i++) { // patchp = getPatch(0, i); // neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i); patchp = getPatch(0, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + neighbor_offset[1]); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateEastEdge(); neighbor_patchp->dirtyZ(); } // Now do northeast/southwest connections //for (i = 1; i < mPatchesPerEdge; i++) for (i = 1; i < ppe[1]; i++) { //patchp = getPatch(0, i); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i - 1); patchp = getPatch(0, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i - 1 + neighbor_offset[1]); patchp->connectNeighbor(neighbor_patchp, SOUTHWEST); neighbor_patchp->connectNeighbor(patchp, NORTHEAST); } // Now do northwest/southeast connections //for (i = 0; i < mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[1] - 1; i++) { //patchp = getPatch(0, i); //neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i + 1); patchp = getPatch(0, i + own_offset[1]); neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + 1 + neighbor_offset[1]); patchp->connectNeighbor(neighbor_patchp, NORTHWEST); neighbor_patchp->connectNeighbor(patchp, SOUTHEAST); } } else if (SOUTH == direction) { // Do north/south connections, first //for (i = 0; i < mPatchesPerEdge; i++) for (i = 0; i < ppe[0]; i++) { //patchp = getPatch(i, 0); //neighbor_patchp = neighborp->getPatch(i, mPatchesPerEdge - 1); patchp = getPatch(i + own_offset[0], 0); neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], neighborPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateNorthEdge(); neighbor_patchp->dirtyZ(); } // Now do northeast/southwest connections //for (i = 1; i < mPatchesPerEdge; i++) for (i = 1; i < ppe[0]; i++) { //patchp = getPatch(i, 0); //neighbor_patchp = neighborp->getPatch(i - 1, mPatchesPerEdge - 1); patchp = getPatch(i + own_offset[0], 0); neighbor_patchp = neighborp->getPatch(i + 1 + neighbor_offset[0], neighborPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, SOUTHWEST); neighbor_patchp->connectNeighbor(patchp, NORTHEAST); } // Now do northeast/southwest connections //for (i = 0; i < mPatchesPerEdge - 1; i++) for (i = 0; i < ppe[0] - 1; i++) { // patchp = getPatch(i, 0); // neighbor_patchp = neighborp->getPatch(i + 1, mPatchesPerEdge - 1); patchp = getPatch(i + own_offset[0], 0); neighbor_patchp = neighborp->getPatch(i + 1 + neighbor_offset[0], neighborPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, SOUTHEAST); neighbor_patchp->connectNeighbor(patchp, NORTHWEST); } } }
void LLSurface::connectNeighbor(LLSurface *neighborp, U32 direction) { if (gNoRender) { return; } S32 i; LLSurfacePatch *patchp, *neighbor_patchp; mNeighbors[direction] = neighborp; neighborp->mNeighbors[gDirOpposite[direction]] = this; // Connect patches if (NORTHEAST == direction) { patchp = getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(0, 0); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateNorthEdge(); // Only update one of north or east. patchp->dirtyZ(); } else if (NORTHWEST == direction) { patchp = getPatch(0, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, 0); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); } else if (SOUTHWEST == direction) { patchp = getPatch(0, 0); neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateNorthEdge(); // Only update one of north or east. neighbor_patchp->dirtyZ(); } else if (SOUTHEAST == direction) { patchp = getPatch(mPatchesPerEdge - 1, 0); neighbor_patchp = neighborp->getPatch(0, mPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); } else if (EAST == direction) { // Do east/west connections, first for (i = 0; i < (S32)mPatchesPerEdge; i++) { patchp = getPatch(mPatchesPerEdge - 1, i); neighbor_patchp = neighborp->getPatch(0, i); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateEastEdge(); patchp->dirtyZ(); } // Now do northeast/southwest connections for (i = 0; i < (S32)mPatchesPerEdge - 1; i++) { patchp = getPatch(mPatchesPerEdge - 1, i); neighbor_patchp = neighborp->getPatch(0, i+1); patchp->connectNeighbor(neighbor_patchp, NORTHEAST); neighbor_patchp->connectNeighbor(patchp, SOUTHWEST); } // Now do southeast/northwest connections for (i = 1; i < (S32)mPatchesPerEdge; i++) { patchp = getPatch(mPatchesPerEdge - 1, i); neighbor_patchp = neighborp->getPatch(0, i-1); patchp->connectNeighbor(neighbor_patchp, SOUTHEAST); neighbor_patchp->connectNeighbor(patchp, NORTHWEST); } } else if (NORTH == direction) { // Do north/south connections, first for (i = 0; i < (S32)mPatchesPerEdge; i++) { patchp = getPatch(i, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i, 0); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); patchp->updateNorthEdge(); patchp->dirtyZ(); } // Do northeast/southwest connections for (i = 0; i < (S32)mPatchesPerEdge - 1; i++) { patchp = getPatch(i, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i+1, 0); patchp->connectNeighbor(neighbor_patchp, NORTHEAST); neighbor_patchp->connectNeighbor(patchp, SOUTHWEST); } // Do southeast/northwest connections for (i = 1; i < (S32)mPatchesPerEdge; i++) { patchp = getPatch(i, mPatchesPerEdge - 1); neighbor_patchp = neighborp->getPatch(i-1, 0); patchp->connectNeighbor(neighbor_patchp, NORTHWEST); neighbor_patchp->connectNeighbor(patchp, SOUTHEAST); } } else if (WEST == direction) { // Do east/west connections, first for (i = 0; i < mPatchesPerEdge; i++) { patchp = getPatch(0, i); neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateEastEdge(); neighbor_patchp->dirtyZ(); } // Now do northeast/southwest connections for (i = 1; i < mPatchesPerEdge; i++) { patchp = getPatch(0, i); neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i - 1); patchp->connectNeighbor(neighbor_patchp, SOUTHWEST); neighbor_patchp->connectNeighbor(patchp, NORTHEAST); } // Now do northwest/southeast connections for (i = 0; i < mPatchesPerEdge - 1; i++) { patchp = getPatch(0, i); neighbor_patchp = neighborp->getPatch(mPatchesPerEdge - 1, i + 1); patchp->connectNeighbor(neighbor_patchp, NORTHWEST); neighbor_patchp->connectNeighbor(patchp, SOUTHEAST); } } else if (SOUTH == direction) { // Do north/south connections, first for (i = 0; i < mPatchesPerEdge; i++) { patchp = getPatch(i, 0); neighbor_patchp = neighborp->getPatch(i, mPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, direction); neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]); neighbor_patchp->updateNorthEdge(); neighbor_patchp->dirtyZ(); } // Now do northeast/southwest connections for (i = 1; i < mPatchesPerEdge; i++) { patchp = getPatch(i, 0); neighbor_patchp = neighborp->getPatch(i - 1, mPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, SOUTHWEST); neighbor_patchp->connectNeighbor(patchp, NORTHEAST); } // Now do northeast/southwest connections for (i = 0; i < mPatchesPerEdge - 1; i++) { patchp = getPatch(i, 0); neighbor_patchp = neighborp->getPatch(i + 1, mPatchesPerEdge - 1); patchp->connectNeighbor(neighbor_patchp, SOUTHEAST); neighbor_patchp->connectNeighbor(patchp, NORTHWEST); } } }
void swm::Geom::delPatch(string const & id) { swm::Patch * patch = getPatch(id); delete(patch); }
int main(void) { LinkedList List; u16 * ship = NULL; GBA_STATE state = GBA_STARTING; int i; int sze = 3; int time = 0; int rate = 10; int tlRow = 1; int tlCol = 2; int H = 21; int W = 32; int row = 80 - H; int col = 240 - W; LLNode * here; ship = (u16 *) malloc(H * W); fillPatch(ship,(u16 *) ShipBitmap, tlRow, tlCol, H, W); for(i = 0; i < 4; i++) colorIndex[i] = findbestColor(COLOR(12 + 4*i, 0, 0), StarrySkyPal); load_palette((u16 *) StarrySkyPal); List = emptyList(); setup(); while (1) { waitForScan(); flipPage(); switch (state) { case GBA_STARTING: copy_full_screen((u16 *) Start_ScreenBitmap); if (check_key(BUTTON_NDX_START) == KEY_RELEASED) { state = GBA_RUNNING; } break; case GBA_RUNNING: if(KEY_DOWN_NOW(BUTTON_DOWN)&&(row<(SCREEN_HEIGHT - H))) row++; if(KEY_DOWN_NOW(BUTTON_UP)&&(row > 0)) row--; if(KEY_DOWN_NOW(BUTTON_RIGHT)&&(col < SCREEN_WIDTH - W)) col++; if(KEY_DOWN_NOW(BUTTON_LEFT)&&(col>0)) col--; if (time % rate == 0) { /*random size for the Astroids*/ addAstroid(&List, sze + (rand() % 4)); } time++; update(&List); copy_full_screen((u16 *) StarrySkyBitmap); getPatch(ship, row, col, H, W); display(List); here = List.head; /*Collision Detection*/ while(here){ if((here->data->row > (row - here->data->side)) && (here->data->row < (row + H)) && (here->data->col == col + 10)){ state = GBA_STARTING; break; } here = here->next; } break; } } delete(&List); free(ship); return 0; }
/* * Iterate over every contour point in contours and compute the * priority of path centered at point using grayMat and confidenceMat */ void computePriority(const contours_t& contours, const cv::Mat& grayMat, const cv::Mat& confidenceMat, cv::Mat& priorityMat) { assert(grayMat.type() == CV_32FC1 && priorityMat.type() == CV_32FC1 && confidenceMat.type() == CV_32FC1 ); // define some patches cv::Mat confidencePatch; cv::Mat magnitudePatch; cv::Point2f normal; cv::Point maxPoint; cv::Point2f gradient; double confidence; // get the derivatives and magnitude of the greyscale image cv::Mat dx, dy, magnitude; getDerivatives(grayMat, dx, dy); cv::magnitude(dx, dy, magnitude); // mask the magnitude cv::Mat maskedMagnitude(magnitude.size(), magnitude.type(), cv::Scalar_<float>(0)); magnitude.copyTo(maskedMagnitude, (confidenceMat != 0.0f)); cv::erode(maskedMagnitude, maskedMagnitude, cv::Mat()); assert(maskedMagnitude.type() == CV_32FC1); // for each point in contour cv::Point point; for (int i = 0; i < contours.size(); ++i) { contour_t contour = contours[i]; for (int j = 0; j < contour.size(); ++j) { point = contour[j]; confidencePatch = getPatch(confidenceMat, point); // get confidence of patch confidence = cv::sum(confidencePatch)[0] / (double) confidencePatch.total(); assert(0 <= confidence && confidence <= 1.0f); // get the normal to the border around point normal = getNormal(contour, point); // get the maximum gradient in source around patch magnitudePatch = getPatch(maskedMagnitude, point); cv::minMaxLoc(magnitudePatch, NULL, NULL, NULL, &maxPoint); gradient = cv::Point2f( -getPatch(dy, point).ptr<float>(maxPoint.y)[maxPoint.x], getPatch(dx, point).ptr<float>(maxPoint.y)[maxPoint.x] ); // set the priority in priorityMat priorityMat.ptr<float>(point.y)[point.x] = std::abs((float) confidence * gradient.dot(normal)); assert(priorityMat.ptr<float>(point.y)[point.x] >= 0); } } }
void LLSurface::createPatchData() { // Assumes mGridsPerEdge, mGridsPerPatchEdge, and mPatchesPerEdge have been properly set // TODO -- check for create() called when surface is not empty S32 i, j; LLSurfacePatch *patchp; // Allocate memory mPatchList = new LLSurfacePatch[mNumberOfPatches]; // One of each for each camera mVisiblePatchCount = mNumberOfPatches; for (j=0; j<mPatchesPerEdge; j++) { for (i=0; i<mPatchesPerEdge; i++) { patchp = getPatch(i, j); patchp->setSurface(this); } } for (j=0; j<mPatchesPerEdge; j++) { for (i=0; i<mPatchesPerEdge; i++) { patchp = getPatch(i, j); patchp->mHasReceivedData = FALSE; patchp->mSTexUpdate = TRUE; S32 data_offset = i * mGridsPerPatchEdge + j * mGridsPerPatchEdge * mGridsPerEdge; patchp->setDataZ(mSurfaceZ + data_offset); patchp->setDataNorm(mNorm + data_offset); // We make each patch point to its neighbors so we can do resolution checking // when butting up different resolutions. Patches that don't have neighbors // somewhere will point to NULL on that side. if (i < mPatchesPerEdge-1) { patchp->setNeighborPatch(EAST,getPatch(i+1, j)); } else { patchp->setNeighborPatch(EAST, NULL); } if (j < mPatchesPerEdge-1) { patchp->setNeighborPatch(NORTH, getPatch(i, j+1)); } else { patchp->setNeighborPatch(NORTH, NULL); } if (i > 0) { patchp->setNeighborPatch(WEST, getPatch(i - 1, j)); } else { patchp->setNeighborPatch(WEST, NULL); } if (j > 0) { patchp->setNeighborPatch(SOUTH, getPatch(i, j-1)); } else { patchp->setNeighborPatch(SOUTH, NULL); } if (i < (mPatchesPerEdge-1) && j < (mPatchesPerEdge-1)) { patchp->setNeighborPatch(NORTHEAST, getPatch(i + 1, j + 1)); } else { patchp->setNeighborPatch(NORTHEAST, NULL); } if (i > 0 && j < (mPatchesPerEdge-1)) { patchp->setNeighborPatch(NORTHWEST, getPatch(i - 1, j + 1)); } else { patchp->setNeighborPatch(NORTHWEST, NULL); } if (i > 0 && j > 0) { patchp->setNeighborPatch(SOUTHWEST, getPatch(i - 1, j - 1)); } else { patchp->setNeighborPatch(SOUTHWEST, NULL); } if (i < (mPatchesPerEdge-1) && j > 0) { patchp->setNeighborPatch(SOUTHEAST, getPatch(i + 1, j - 1)); } else { patchp->setNeighborPatch(SOUTHEAST, NULL); } LLVector3d origin_global; origin_global.mdV[0] = mOriginGlobal.mdV[0] + i * mMetersPerGrid * mGridsPerPatchEdge; origin_global.mdV[1] = mOriginGlobal.mdV[0] + j * mMetersPerGrid * mGridsPerPatchEdge; origin_global.mdV[2] = 0.f; patchp->setOriginGlobal(origin_global); } } }
QList<QVariant> Version::toArray() { return {getMajor(), getMinor(), getPatch(), getBuild(), getRelease()}; }