typename CollapsedAKQReducedCubSComplexSupplier<Traits>::CellDescriptor* CollapsedAKQReducedCubSComplexSupplier<Traits>::CreateCell(CubCellSetPtr cubCellSet, BitCoordIterator& it, size_t dim) { size_t index = _cellsCountByDim[dim]++; CellDescriptor* cell = new CellDescriptor(index, dim); _allCells.push_back(cell); _cellsMapByDim[dim][it] = cell; std::vector<BitCoordIterator> faces; std::vector<int> coefficients; if (dim == 2) // hack to obtain proper order of 2boundary { cubCellSet().getOrdered2Faces(it, faces, coefficients); } else { cubCellSet().getFaces(it, faces, coefficients); } typename std::vector<BitCoordIterator>::iterator fIt = faces.begin(); typename std::vector<BitCoordIterator>::iterator fItEnd = faces.end(); std::vector<int>::iterator cIt = coefficients.begin(); for ( ; fIt != fItEnd; ++fIt) { cell->_faces.push_back(AddCell(cubCellSet, *fIt, dim - 1)); cell->_coefficients.push_back(*cIt); cIt++; } // adding null point cell to each "non complete" 1-cell boundary if (dim == 1 && cell->_faces.size() < 2) { if (cell->_faces.size() == 0) { //cell->_faces.push_back(_nullSetCell); //cell->_faces.push_back(_nullSetCell); //cell->_coefficients.push_back(1); //cell->_coefficients.push_back(0); } else if (cell->_coefficients[0] == 1) { cell->_faces.push_back(_nullSetCell); cell->_coefficients.push_back(-1); } else // if (cell->_coefficients[0] == -1) { cell->_faces.push_back(cell->_faces[0]); cell->_coefficients.push_back(-1); cell->_faces[0] = _nullSetCell; cell->_coefficients[0] = 1; } } return cell; }
void scRedispList::SetImmediateRect( scColumn* col, const scImmediateRedisp& immedredisp ) { Lock(); scColRedisplay* cell = FindCell( col ); if ( !cell ) { Unlock(); AddCell( col ); Lock(); cell = FindCell( col ); } cell->fImmediateRedisplay = true; cell->fImmediateArea = immedredisp; Unlock(); }
/* Calculates one pixel from output map, given the input maps. * Puts all values of input pixels in a list and determines the value of * the output pixel according to these values and the overlapping areas. * Returns 0 if no error occurs, 1 otherwise. */ static int CalcPixel( MAP *out, /* write-only output map */ MAP **in, /* read-only list input maps */ size_t nrCoverCells, /* min. nr. non-MV cells for non-MV */ size_t nrMaps, /* nr. of input maps */ double rOut, /* row number pixel */ double cOut, /* column number pixel */ BOOL aligned, /* maps are aligned */ REAL8 angle) /* angle of output map */ { PTYPE tlX, tlY, trX, trY, brX, brY, blX, blY; double r, c; DATA *list = NULL; /* areas and values of input cells */ size_t i, nrList = 0; /* number of items in list */ POINT2D *outputCell; /* polygon of output cell */ size_t nr = 4; /* nr of points of cell */ CSF_VS vs; /* value scale of first input map */ if(nrCoverCells > 0 && nrMaps > 1) raster = InitRaster(raster); /* initialize the raster */ /* Determine the four corners of output pixel */ RrowCol2Coords(out, rOut, cOut, &tlX, &tlY); /* top left */ RrowCol2Coords(out, rOut, cOut + 1, &trX, &trY); /* top right */ RrowCol2Coords(out, rOut + 1, cOut, &blX, &blY); /* bottom left */ RrowCol2Coords(out, rOut + 1, cOut + 1, &brX, &brY); /* bottom right */ outputCell = PutInPol(tlX, tlY, trX, trY, brX, brY, blX, blY); if(outputCell == NULL) return 1; POSTCOND(outputCell[0].x == outputCell[nr].x); POSTCOND(outputCell[0].y == outputCell[nr].y); /* Get pixel on every input map */ for(i = 0; i < nrMaps; i++) { MAP *X = in[i]; /* input map number i */ PTYPE tlC, tlR, trC, trR, brC, brR, blC, blR; PTYPE tlX2, tlY2, trX2, trY2, brX2, brY2, blX2, blY2; double leftB, belowB, rightB, upperB; /* boundaries */ /* Corners: (tlX, tlY), (trX, trY), (blX, blY) and * (brX, brY). Translate for input map. */ Rcoords2RowCol(X, tlX, tlY, &tlC, &tlR); /* top left */ Rcoords2RowCol(X, trX, trY, &trC, &trR); /* top right */ Rcoords2RowCol(X, blX, blY, &blC, &blR); /* bottom left */ Rcoords2RowCol(X, brX, brY, &brC, &brR); /* bottom right */ /* Boundaries in the input map */ rightB = ceil(MaxPoint(tlR, trR, blR, brR)); belowB = ceil(MaxPoint(tlC, trC, blC, brC)); leftB = floor(MinPoint(tlR, trR, blR, brR)); upperB = floor(MinPoint(tlC, trC, blC, brC)); PRECOND(upperB <= belowB); PRECOND(leftB <= rightB); /* Check all cells between the boundaries */ for(r = upperB; r < belowB; r++) { REAL8 *currRow; if(0 <= r && r <= RgetNrRows(X)) currRow = (REAL8 *)CacheGetRow(in, i, r); for(c = leftB; c < rightB; c++) { /* Cells that might be in pixel */ POINT2D *inputCell; /* polygon input cell */ if(r < 0 || RgetNrRows(X) <= r || c < 0 || RgetNrCols(X) <= c) continue; /* Top left & right, bottom left & right */ RrowCol2Coords(X, r, c, &tlX2, &tlY2); RrowCol2Coords(X, r, c+1, &trX2, &trY2); RrowCol2Coords(X, r+1, c, &blX2, &blY2); RrowCol2Coords(X, r+1, c+1, &brX2, &brY2); inputCell = PutInPol(tlX2, tlY2, trX2, trY2, brX2, brY2, blX2, blY2); if(inputCell == NULL) return 1; POSTCOND(inputCell[0].x == inputCell[nr].x); POSTCOND(inputCell[0].y == inputCell[nr].y); /* Add item to list for cell */ if(AddCell(&list, raster, &nrList, inputCell, outputCell, currRow, X, nrMaps, (size_t)c, nrCoverCells, aligned, angle)) return 1; Free(inputCell); /* deallocate */ } } } /* calculate output value of pixel according value scale */ vs = RgetValueScale(in[0]); if(vs != VS_DIRECTION) CalcScalarOut(out, (size_t)rOut, (size_t)cOut, nrList, list, nrCoverCells, nrMaps); else CalcDirectionOut(out, (size_t) rOut, (size_t) cOut, nrList, list, nrCoverCells, nrMaps); Free(outputCell); /* deallocate */ Free(list); /* deallocate */ return 0; /* successfully terminated */ }
////////////////////////////////////////////////////////////////////////// // Given the position, normal, and set of rays compute the bent normal and // occlusion term. ////////////////////////////////////////////////////////////////////////// void ComputeOcclusion (NmRawPointD* newPos, NmRawPointD* newNorm, int numTris, NmRawTriangle* tri, AtiOctree* octree, int numRays, NmRawPointD* rays, double* rayWeights, NmRawPointD* bentNormal, double* occlusion, int& gMaxCells, AtiOctreeCell** &gCell) { #ifdef _DEBUG if ((newPos == NULL) || (newNorm == NULL) || (tri == NULL) || (octree == NULL) || (rays == NULL) || (rayWeights == NULL) || (bentNormal == NULL) || (occlusion == NULL)) { //NmPrint ("ERROR: Incorrect arguments passed!\n"); exit (-1); } #endif // Clear results. // Bent normal should at minimum be the regular normal (I think). bentNormal->x = newNorm->x; bentNormal->y = newNorm->y; bentNormal->z = newNorm->z; (*occlusion) = 0.0; double hit = 0.0f; double num = 0.0f; // Compute offset vertex NmRawPointD pos; pos.x = newPos->x + (newNorm->x * gDistanceOffset); pos.y = newPos->y + (newNorm->y * gDistanceOffset); pos.z = newPos->z + (newNorm->z * gDistanceOffset); // Compute rotation matrix to match hemisphere to normal double rotMat[16]; FromToRotation (rotMat, gZVec, newNorm->v); // Shoot the rays for (int r = 0; r < numRays; r++) { // First rotate the ray into position NmRawPointD oRay; oRay.x = rays[r].x*rotMat[0] + rays[r].y*rotMat[4] + rays[r].z*rotMat[8]; oRay.y = rays[r].x*rotMat[1] + rays[r].y*rotMat[5] + rays[r].z*rotMat[9]; oRay.z = rays[r].x*rotMat[2] + rays[r].y*rotMat[6] + rays[r].z*rotMat[10]; // Walk the Octree to find triangle intersections. bool intersect = false; int numCells = 0; int cellCount = 0; int triCount = 0; AddCell (octree->m_root, &numCells, gMaxCells, gCell); while ((numCells > 0) && !intersect) { // Take the cell from the list. cellCount++; numCells--; AtiOctreeCell* currCell = gCell[numCells]; // See if this is a leaf node bool leaf = true; for (int c = 0; c < 8; c++) { if (currCell->m_children[c] != NULL) { leaf = false; break; } } // If we are a leaf check the triangles if (leaf) { // Run through the triangles seeing if the ray intersects. for (int t = 0; t < currCell->m_numItems; t++) { // Save off current triangle. NmRawTriangle* currTri = &(tri[currCell->m_item[t]]); triCount++; // See if it intersects. double oT, oU, oV; if (IntersectTriangle (pos.v, oRay.v, currTri->vert[0].v, currTri->vert[1].v, currTri->vert[2].v, &oT, &oU, &oV)) { if (oT > 0.0f) { intersect = true; break; } } } // end for t (num triangles in this cell) } // end if leaf else { // Non-leaf, add the children to the list if their bounding // box intersects the ray. for (int c = 0; c < 8; c++) { if (currCell->m_children[c] != NULL) { // Save off current child. AtiOctreeCell* child = currCell->m_children[c]; // If the ray intersects the box if (RayIntersectsBox (&pos, &oRay, &child->m_boundingBox)) { AddCell (child, &numCells, gMaxCells, gCell); } // end if the ray intersects this bounding box. // else do nothing, we'll never intersect any triangles // for it's children. } // end if we have a cell } // end for c (8 children) } // end else non-leaf node. } // end while cells // Update our running results based on if we found and intersection. num += rayWeights[r]; if (!intersect) { bentNormal->x += (oRay.x * rayWeights[r]); bentNormal->y += (oRay.y * rayWeights[r]); bentNormal->z += (oRay.z * rayWeights[r]); } else { hit += rayWeights[r]; } /* // Save off some stats. if (triCount > gAOMaxTrisTested) { gAOMaxTrisTested = triCount; } if (cellCount > gAOMaxCellsTested) { gAOMaxCellsTested = cellCount; } */ } // end for r (number of rays) // Normalize result Normalize (bentNormal->v); (*occlusion) = (num - hit) / num; } // end of ComputeOcclusion
////////////////////////////////////////////////////////////////////////// // Figure out if we have an intersection from the given point, if we do // make sure it's the "best" one. Returns true if it found an intersection // false otherwise. It places the normal into newNormal and position into // newPos. ////////////////////////////////////////////////////////////////////////// inline bool FindBestIntersection (NmRawPointD& pos, NmRawPointD& norm, AtiOctree* octree, NmRawTriangle* highTris, NmTangentMatrix* hTangentSpace, float* bumpMap, int bumpHeight, int bumpWidth, double newNorm[3], double newPos[3], double* displacement, int gNormalRules, double gMaxAngle, double gDistance, double gEpsilon, int& gMaxCells, AtiOctreeCell** &gCell) { // Clear outputs. newNorm[0] = 0.0; newNorm[1] = 0.0; newNorm[2] = 0.0; newPos[0] = 0.0; newPos[1] = 0.0; newPos[2] = 0.0; // Create negative normal NmRawPointD negNorm; negNorm.x = -norm.x; negNorm.y = -norm.y; negNorm.z = -norm.z; // Some stats. int cellCount = 0; int hitTriCount = 0; int triCount = 0; // Walk the octree looking for intersections. NmRawPointD intersect; NmRawPointD lastIntersect; int numCells = 0; AddCell (octree->m_root, &numCells, gMaxCells, gCell); while (numCells > 0) { // Take the cell from the list. cellCount++; numCells--; AtiOctreeCell* currCell = gCell[numCells]; // See if this is a leaf node bool leaf = true; for (int c = 0; c < 8; c++) { if (currCell->m_children[c] != NULL) { leaf = false; break; } } // If we are a leaf check the triangles if (leaf) { // Run through the triangles seeing if the ray intersects. for (int t = 0; t < currCell->m_numItems; t++) { // Save off current triangle. NmRawTriangle* hTri = &highTris[currCell->m_item[t]]; // See if it intersects. triCount++; if (IntersectTriangle (pos.v, norm.v, hTri->vert[0].v, hTri->vert[1].v, hTri->vert[2].v, &intersect.x, &intersect.y, &intersect.z)) { // Keep some statistics. hitTriCount++; // Figure out new normal and position double b0 = 1.0 - intersect.y - intersect.z; double np[3]; double nn[3]; BaryInterpolate (hTri, b0, intersect.y, intersect.z, np, nn); // Debug this intersection test if requested. // See if this should be the normal for the map. if (IntersectionIsBetter (gNormalRules, &norm, nn, &intersect, newNorm, &lastIntersect, gMaxAngle, gDistance, gEpsilon)) { // Perturb by bump map if (bumpMap != NULL) { GetPerturbedNormal (hTri, b0, intersect.y, intersect.z, bumpMap, bumpWidth, bumpHeight, hTangentSpace[currCell->m_item[t]].m, nn); } // Copy over values memcpy (newNorm, nn, sizeof (double)*3); memcpy (newPos, np, sizeof (double)*3); memcpy (&lastIntersect, &intersect, sizeof (NmRawPointD)); } // end if this intersection is better #ifdef DEBUG_INTERSECTION else if (gDbgIntersection) { NmPrint (" <<< Intersection is worse!\n"); } #endif } // end if we have an intersection } // end for t (num triangles in this cell) } // end if leaf else { // Non-leaf, add the children to the list if their bounding // box intersects the ray. for (int c = 0; c < 8; c++) { if (currCell->m_children[c] != NULL) { // Save off current child. AtiOctreeCell* child = currCell->m_children[c]; // If the ray intersects the box if (RayIntersectsBox (&pos, &norm, &child->m_boundingBox)) { AddCell (child, &numCells, gMaxCells, gCell); } // end if the ray intersects this bounding box. else if (RayIntersectsBox (&pos, &negNorm, &child->m_boundingBox)) { AddCell (child, &numCells, gMaxCells, gCell); } // end if the ray intersects this bounding box. // else do nothing, we'll never intersect any triangles // for it's children. } // end if we have a cell } // end for c (8 children) } // end else non-leaf node. } // end while cells /* // Save off some stats. if (triCount > gMaxTrisTested) { gMaxTrisTested = triCount; } if (hitTriCount > gMaxTrisHit) { gMaxTrisHit = hitTriCount; } if (cellCount > gMaxCellsTested) { gMaxCellsTested = cellCount; } */ // Test if we found an intersection. if ( (newNorm[0] != 0.0) || (newNorm[1] != 0.0) || (newNorm[2] != 0.0) ) { (*displacement) = lastIntersect.x; return true; } return false; } // end of FindBestIntersection
ThreadInspectorTest::ThreadInspectorTest() : nuiVBox(0), mThreadCount(0), mEventSink(this) { SetExpand(nuiExpandShrinkAndGrow); // explanations nuiLabel* pLabel = new nuiLabel(_T("Open the nuiIntrospector(SHIFT+CTRL+D), go to the Thread Inspector, run the Thread Checker, play with the test tool below, and see how the Thread Inspector reacts.\n\nIf you create a dead-lock, the nglThreadChecker will make the application exit, and dump usefull information on the standart output.\n")); pLabel->SetWrapping(true); AddCell(pLabel); SetCellMinPixels(0, 90); //*********************************** // test tool nuiDecoration* pDeco = new nuiGradientDecoration(_T("ThreadInspectorTestDeco"), nuiRect(3, 3, 0, 0), nuiColor(246,246,246), nuiColor(220,220,220), nuiColor(210,210,210), nuiColor(255,255,255), nuiVertical, 1, nuiColor(180,180,180), eStrokeAndFillShape); // buttons pLabel = new nuiLabel(_T("test for Critical Sections locking")); pLabel->SetDecoration(pDeco, eDecorationBorder); AddCell(pLabel); nuiHBox* pBox = new nuiHBox(0); AddCell(pBox); nuiButton* pCreateBtn = new nuiButton(_T("Create CS Thread")); pBox->AddCell(pCreateBtn); mEventSink.Connect(pCreateBtn->Activated, &ThreadInspectorTest::CreateCSThread); nuiButton* pRemoveBtn = new nuiButton(_T("Terminate CS Thread")); pBox->AddCell(pRemoveBtn); mEventSink.Connect(pRemoveBtn->Activated, &ThreadInspectorTest::RemoveCSThread); // threads list mpCSList = new nuiList(); AddCell(mpCSList); AddCell(NULL); SetCellPixels(GetNbCells()-1, 15); pLabel = new nuiLabel(_T("test for Light Locks locking")); pLabel->SetDecoration(pDeco, eDecorationBorder); AddCell(pLabel); pBox = new nuiHBox(0); AddCell(pBox); pCreateBtn = new nuiButton(_T("Create LL Thread")); pBox->AddCell(pCreateBtn); mEventSink.Connect(pCreateBtn->Activated, &ThreadInspectorTest::CreateLLThread); pRemoveBtn = new nuiButton(_T("Terminate LL Thread")); pBox->AddCell(pRemoveBtn); mEventSink.Connect(pRemoveBtn->Activated, &ThreadInspectorTest::RemoveLLThread); // threads list mpLLList = new nuiList(); AddCell(mpLLList); }
Row::Row(const std::string& cell) { INFO(cell); Initialize(); AddCell(cell); }
void ImageTable::AddCell(const FilePath& f){ AddCell(f.StripPath()); }