void CornerSequence::setMacrosPositionByCorners() { for (int i = 0; i < macros->size(); ++i) { Macro *macro = macros->at(i); macro->setOrientation(orientations->at(i)); Corner *corner = corners->at(i); switch (corner->getDirection()) { case 0: macro->setXStart(corner->getX()); macro->setYStart(corner->getY()); break; case 1: macro->setXEnd(corner->getX()); macro->setYStart(corner->getY()); break; case 2: macro->setXStart(corner->getX()); macro->setYEnd(corner->getY()); break; case 3: macro->setXEnd(corner->getX()); macro->setYEnd(corner->getY()); break; } macro->updateRectanglesPosition(); } }
void keepTrackingCornersAndFindObjectLocationPixels(vector<Point> &corners) { left_corner_.trackCorner(corners, right_corner_); right_corner_.trackCorner(corners, left_corner_); object_location_pixels_x_ = left_corner_.point_.x + corner_distance_ /2 - image_middle_x_; cout << "Delta X by pixels " << object_location_pixels_x_ << endl; }
Point Size::getCornerCoords(const Point& p, const Corner& c) { Point rel = p; if (c.getX() == Right) rel.x = getWidth() - 1 - rel.x; if (c.getY() == Bottom) rel.y = getHeight() - 1 - rel.y; return rel; }
void CornerSequence::changeCorner(int i) { Corner *corner = corners->at(i); if (corner != 0) { if (corner->isNotFromTilePlane()) { delete corner; } corners->at(i) = 0; } }
string Graph::currentGraphType() { int count = 0; bool weighted = false; bool directional = false; bool pseudoGraph = false; string graphTypes = "This graph is: "; vector<Vertex *> vertexes = getVertexes(); for (vector<Vertex *>::iterator it = vertexes.begin(); it != vertexes.end(); it++) { Vertex *vertex = *it; vector<Adjacency *> adjacencies = vertex->getAdjacencies(); for (vector<Adjacency *>::iterator secondIt = adjacencies.begin(); secondIt != adjacencies.end(); secondIt++) { Adjacency *adjacency = *secondIt; Corner *corner = adjacency->getCorner(); Vertex *convergent = corner->getConvergent(); Vertex *divergent = corner->getDivergent(); if (!weighted && corner->getWeight() != -1) { weighted = true; } if (!pseudoGraph && corner->isCycle()) { pseudoGraph = true; } if (!directional && (convergent == nullptr || divergent == nullptr)) { directional = true; } count++; } } if (directional) { graphTypes += " -> directional"; } if (!directional && count != 0) { graphTypes += " -> not directional"; } if (weighted) { graphTypes += " -> weighted"; } if (pseudoGraph) { graphTypes += " -> pseudoGraph"; } if (count == 0) { graphTypes += " -> null graph"; } return graphTypes; }
Point Patch::K(int ei, int i){ Corner* ci = C(ei); Spline* c = ci->E()->pData->pCurve; /*if (!c) return (i<2)?(ci->P()*(1-i) + ci->next()->P()*i) : (ci->P()*(i-2) + ci->next()->P()*(1-t));*/ bool curvedir = (ci->V()->pData->pP() == c->pCV(0)); bool rev = ((ei>1) && curvedir) || ( (ei<2) && !curvedir); return (rev)?c->CV(3-i):c->CV(i); }
void CornerSequence::randomizeSequence(int start) { // Macros std::random_shuffle(macros->begin() + start, macros->end()); // Corners for (int i = 0; i < corners->size(); ++i) { Corner *corner = corners->at(i); if (corner != 0) { if (corner->isNotFromTilePlane()) { delete corner; } corners->at(i) = 0; } } }
void Graph::updateAllWeight(Vertex *vertex) { vector<Adjacency *> adjacencies = vertex->getAdjacencies(); for (vector<Adjacency *>::iterator it = adjacencies.begin(); it != adjacencies.end(); it++) { Adjacency *adjacency = *it; Corner *corner = adjacency->getCorner(); if (corner->getWeight() == -1) { corner->setWeight(0); } } }
CornerSequence::CornerSequence(int xStart, int yStart, int xEnd, int yEnd, int numMacros, //std::set<Macro *, CompareMacroWidth> *initialWidthSortedMacros, //std::set<Macro *, CompareMacroHeight> *initialHeightSortedMacros) { SortedMacros *initialWidthSortedMacros, SortedMacros *initialHeightSortedMacros) { fixedMacros = new std::vector<Macro *>(); macros = new std::vector<Macro *>(); corners = new std::vector<Corner *>(); orientations = new std::vector<int>(numMacros, 0); macros->reserve(numMacros); corners->reserve(numMacros); cornerHorizontalTilePlane = new CornerHorizontalTilePlane(xStart, yStart, xEnd, yEnd); cornerVerticalTilePlane = new CornerVerticalTilePlane(xStart, yStart, xEnd, yEnd); cornerHorizontalTilePlane->coupleWithCornerVerticalTilePlane(cornerVerticalTilePlane); cornerHorizontalTilePlane->calculateCurrentCornersWidthAndHeight(); cornerVerticalTilePlane->calculateCurrentCornersWidthAndHeight(); sizeQuadtree = new Quadtree(0, 0, xEnd - xStart + 1, yEnd - yStart + 1, new CornerSize()); // +1 for containing Corners with the size of floorplan. positionQuadtree = new Quadtree(xStart, yStart, xEnd + 1, yEnd + 1, new CornerPosition()); // Insert Corners to quadtrees. std::vector<Corner *> *createdCorners = cornerHorizontalTilePlane->getCurrentlyCreatedCorners(); for (int i = 0; i < createdCorners->size(); ++i) { Corner *corner = createdCorners->at(i); corner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(corner); positionQuadtree->insert(corner); } createdCorners = cornerVerticalTilePlane->getCurrentlyCreatedCorners(); for (int i = 0; i < createdCorners->size(); ++i) { Corner *corner = createdCorners->at(i); corner->updateWidthAndHeightForSorting(); if (corner->isType1()) { sizeQuadtree->insert(corner); positionQuadtree->insert(corner); } } this->initialWidthSortedMacros = initialWidthSortedMacros; this->initialHeightSortedMacros = initialHeightSortedMacros; //widthSortedMacros = new std::set<Macro *, CompareMacroWidth>(*initialWidthSortedMacros); //heightSortedMacros = new std::set<Macro *, CompareMacroHeight>(*initialHeightSortedMacros); //widthSortedMacros = new SortedMacros(initialWidthSortedMacros); //heightSortedMacros = new SortedMacros(initialHeightSortedMacros); widthSortedMacros = new SortedMacros(true); heightSortedMacros = new SortedMacros(true); indexPlacedUnsuccessfully = numMacros; }
CornerSequence::~CornerSequence() { delete macros; for (int i = 0; i < corners->size(); ++i) { Corner *corner = corners->at(i); if (corner != 0 && corner->isNotFromTilePlane()) { delete corner; } } delete corners; delete orientations; delete cornerHorizontalTilePlane; delete cornerVerticalTilePlane; delete sizeQuadtree; delete positionQuadtree; //delete widthSortedMacros; delete heightSortedMacros; }
CornerSequence *CornerSequence::copy() { CornerSequence *copiedCornerSequence = new CornerSequence( cornerHorizontalTilePlane->getXStart(), cornerHorizontalTilePlane->getYStart(), cornerHorizontalTilePlane->getXEnd(), cornerHorizontalTilePlane->getYEnd(), macros->size(), initialWidthSortedMacros, initialHeightSortedMacros); for (int i = 0; i < fixedMacros->size(); ++i) { copiedCornerSequence->addFixedMacro(fixedMacros->at(i)); } for (int i = 0; i < macros->size(); ++i) { Corner *corner = corners->at(i); if (corner != 0) { corner = corner->copyAsNotFromTilePlane(); } copiedCornerSequence->addMacroCornerPair(macros->at(i), corner); copiedCornerSequence->setOrientation(i, orientations->at(i)); } return copiedCornerSequence; }
Corner * CornerCollection::GetAbove(Corner* corner) { Corner * closet_corner = 0; int smallest_distance = SCREEN_WIDTH; Position * corner_pos = corner->GetPosition(); std::vector<Corner*>::iterator iterador = vector.begin(); for (; iterador < vector.end(); iterador++) { Corner * c = (*iterador); Position * c_pos = c->GetPosition(); int dist = corner_pos->Distance(c_pos); if ((dist != 0) && (dist < smallest_distance) && (corner_pos->SameColumn(c_pos))) { smallest_distance = dist; closet_corner = c; } } return closet_corner; }
ZIntPoint ZIntCuboidFace::getCornerCoordinates(int index) const { ZIntPoint pt; Corner corner = getCorner(index); switch (getAxis()) { case NeuTube::X_AXIS: pt.set(getPlanePosition(), corner.getX(), corner.getY()); break; case NeuTube::Y_AXIS: pt.set(corner.getX(), getPlanePosition(), corner.getY()); break; case NeuTube::Z_AXIS: pt.set(corner.getX(), corner.getY(), getPlanePosition()); break; } return pt; }
bool CornerNode::getValue (const String& strMemberName, String& strValue) { bool bValueSet = false; Corner* pObject = dynamic_cast<Corner*>(m_pObject); if (strMemberName == L"value") { ValueObject* pValueObj = dynamic_cast<ValueObject*>(m_pObject); if (pValueObj) { if (!pValueObj->isNothing()) { strValue = pValueObj->toString(); bValueSet = true; } } } else if (strMemberName == L"StaStart") { if (pObject->hasValue_StaStart()) { strValue = (DoubleObjectImpl(pObject->getStaStart())).toString(); bValueSet = true; } } else if (strMemberName == L"StaEnd") { if (pObject->hasValue_StaEnd()) { strValue = (DoubleObjectImpl(pObject->getStaEnd())).toString(); bValueSet = true; } } else if (strMemberName == L"Type") { if (pObject->hasValue_Type()) { strValue = (EnumCornerTypeImpl(pObject->getType())).toString(); bValueSet = true; } } return bValueSet; }
bool CornerNode::setValue (const String& strMemberName, const String* pstrValue) { bool bValueSet = false; Corner* pObject = dynamic_cast<Corner*>(m_pObject); if (strMemberName == L"StaStart") { if (!pstrValue) { pObject->resetValue_StaStart(); } else { pObject->setStaStart(DoubleObjectImpl::parseString(pstrValue->c_str(), pstrValue->length())); bValueSet = true; } } if (strMemberName == L"StaEnd") { if (!pstrValue) { pObject->resetValue_StaEnd(); } else { pObject->setStaEnd(DoubleObjectImpl::parseString(pstrValue->c_str(), pstrValue->length())); bValueSet = true; } } if (strMemberName == L"Type") { if (!pstrValue) { pObject->resetValue_Type(); } else { pObject->setType(EnumCornerTypeImpl::parseString(pstrValue->c_str(), pstrValue->length())); bValueSet = true; } } return bValueSet; }
void CornerSequence::fillInWastedRegion() { std::cout << "fillInWastedRegion()\n"; int smallestMacroWidth = widthSortedMacros->getSmallest()->getWidth(); int smallestMacroHeight = heightSortedMacros->getSmallest()->getHeight(); while (true) { int numFills = 0; // Try to fill a horizontal empty Tile. Tile *emptyTile = cornerHorizontalTilePlane->getEmptyTileWithSmallestWidth(); if (emptyTile != 0 && emptyTile->getWidth() < smallestMacroWidth) { std::cout << "fill horizontalTile\n"; emptyTile->print(); Tile *horizontalTile = new Tile(emptyTile->getXStart(), emptyTile->getYStart(), emptyTile->getXEnd(), emptyTile->getYEnd(), true); Tile *verticalTile = new Tile(emptyTile->getXStart(), emptyTile->getYStart(), emptyTile->getXEnd(), emptyTile->getYEnd(), true); horizontalTile->setTemporarilySolid(); verticalTile->setTemporarilySolid(); // Find startVerticalTile. Corner *corner = emptyTile->getBlCorner(); Tile *startVerticalTile; if (corner == 0) { corner = emptyTile->getTlCorner(); } if (corner != 0) { startVerticalTile = corner->getVerticalTile(); } else { // If emptyTile has no Corner, than emptyTile's lb and rt // are empty Tiles, and lb has top Corners and rt has bottom Corners. startVerticalTile = cornerVerticalTilePlane->findTile(emptyTile->getXStart(), emptyTile->getYStart(), emptyTile->getRt()->getBlCorner()->getVerticalTile()); } // Place horizontalTile. std::cout << "place horizontal\n"; cornerHorizontalTilePlane->placeSolidTileGivenBothStartTiles(horizontalTile, emptyTile, startVerticalTile); // Place verticalTile. std::cout << "place vertical\n"; cornerVerticalTilePlane->placeSolidTileGivenBothStartTiles(verticalTile, horizontalTile, startVerticalTile); cornerHorizontalTilePlane->calculateCurrentCornersWidthAndHeight(); cornerVerticalTilePlane->calculateCurrentCornersWidthAndHeight(); std::cout << "updateQuadtrees()\n"; updateQuadtrees(); std::cout << "updateQuadtrees() end\n"; numFills += 1; } // Try to fill a vertical empty Tile. emptyTile = cornerVerticalTilePlane->getEmptyTileWithSmallestHeight(); if (emptyTile != 0 && emptyTile->getHeight() < smallestMacroHeight) { std::cout << "fill verticalTile\n"; emptyTile->print(); Tile *horizontalTile = new Tile(emptyTile->getXStart(), emptyTile->getYStart(), emptyTile->getXEnd(), emptyTile->getYEnd(), true); Tile *verticalTile = new Tile(emptyTile->getXStart(), emptyTile->getYStart(), emptyTile->getXEnd(), emptyTile->getYEnd(), true); horizontalTile->setTemporarilySolid(); verticalTile->setTemporarilySolid(); // Find startHorizontalTile. Corner *corner = emptyTile->getBlCorner(); Tile *startHorizontalTile; if (corner == 0) { corner = emptyTile->getBrCorner(); } if (corner != 0) { corner->print(); startHorizontalTile = corner->getHorizontalTile(); cornerHorizontalTilePlane->getBottomRightMostTile()->print(); } else { // If emptyTile has no Corner, than emptyTile's bl and tr // are empty Tiles, and bl has right Corners and tr has left Corners. startHorizontalTile = cornerHorizontalTilePlane->findTile(emptyTile->getXStart(), emptyTile->getYStart(), emptyTile->getTr()->getBlCorner()->getHorizontalTile()); } // Place horizontalTile. std::cout << "place horizontal\n"; horizontalTile->print(); startHorizontalTile->print(); startHorizontalTile->printFourNeighbors(); cornerHorizontalTilePlane->placeSolidTileGivenBothStartTiles(horizontalTile, startHorizontalTile, emptyTile); // Place verticalTile. std::cout << "place vertical\n"; cornerVerticalTilePlane->placeSolidTileGivenBothStartTiles(verticalTile, horizontalTile, emptyTile); cornerHorizontalTilePlane->calculateCurrentCornersWidthAndHeight(); cornerVerticalTilePlane->calculateCurrentCornersWidthAndHeight(); std::cout << "updateQuadtrees()\n"; updateQuadtrees(); std::cout << "updateQuadtrees() end\n"; numFills += 1; } // Continue or not. if (numFills == 0) { break; } } }
void CornerSequence::updateQuadtrees() { std::vector<Corner *> *currentlyCreatedCorners = cornerHorizontalTilePlane->getCurrentlyCreatedCorners(); std::vector<Corner *> *currentlyModifiedHorizontalCorners = cornerHorizontalTilePlane->getCurrentlyModifiedHorizontalCorners(); std::vector<Corner *> *currentlyModifiedVerticalCorners = cornerHorizontalTilePlane->getCurrentlyModifiedVerticalCorners(); std::vector<Corner *> *currentlyRemovedCorners = cornerHorizontalTilePlane->getCurrentlyRemovedCorners(); for (int j = 0; j < currentlyCreatedCorners->size(); ++j) { Corner *createdCorner = currentlyCreatedCorners->at(j); createdCorner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(createdCorner); positionQuadtree->insert(createdCorner); } for (int j = 0; j < currentlyModifiedHorizontalCorners->size(); ++j) { Corner *modifiedCorner = currentlyModifiedHorizontalCorners->at(j); sizeQuadtree->remove(modifiedCorner); modifiedCorner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(modifiedCorner); } for (int j = 0; j < currentlyModifiedVerticalCorners->size(); ++j) { Corner *modifiedCorner = currentlyModifiedVerticalCorners->at(j); if (modifiedCorner->isType1()) { sizeQuadtree->remove(modifiedCorner); modifiedCorner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(modifiedCorner); } } for (int j = 0; j < currentlyRemovedCorners->size(); ++j) { Corner *removedCorner = currentlyRemovedCorners->at(j); sizeQuadtree->remove(removedCorner); positionQuadtree->remove(removedCorner); delete removedCorner; } currentlyCreatedCorners = cornerVerticalTilePlane->getCurrentlyCreatedCorners(); currentlyModifiedVerticalCorners = cornerVerticalTilePlane->getCurrentlyModifiedVerticalCorners(); currentlyModifiedHorizontalCorners = cornerVerticalTilePlane->getCurrentlyModifiedHorizontalCorners(); std::vector<Corner *> *currentlyChangedToType0Corners = cornerVerticalTilePlane->getCurrentlyChangedToType0Corners(); currentlyRemovedCorners = cornerVerticalTilePlane->getCurrentlyRemovedCorners(); for (int j = 0; j < currentlyCreatedCorners->size(); ++j) { Corner *createdCorner = currentlyCreatedCorners->at(j); if (createdCorner->isType1()) { createdCorner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(createdCorner); positionQuadtree->insert(createdCorner); } } for (int j = 0; j < currentlyModifiedVerticalCorners->size(); ++j) { Corner *modifiedCorner = currentlyModifiedVerticalCorners->at(j); if (modifiedCorner->isType1()) { sizeQuadtree->remove(modifiedCorner); modifiedCorner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(modifiedCorner); } } for (int j = 0; j < currentlyModifiedHorizontalCorners->size(); ++j) { Corner *modifiedCorner = currentlyModifiedHorizontalCorners->at(j); sizeQuadtree->remove(modifiedCorner); modifiedCorner->updateWidthAndHeightForSorting(); sizeQuadtree->insert(modifiedCorner); } for (int j = 0; j < currentlyChangedToType0Corners->size(); ++j) { Corner *changedToType0Corner = currentlyChangedToType0Corners->at(j); sizeQuadtree->remove(changedToType0Corner); positionQuadtree->remove(changedToType0Corner); } for (int j = 0; j < currentlyRemovedCorners->size(); ++j) { Corner *removedCorner = currentlyRemovedCorners->at(j); if (removedCorner->isType1()) { sizeQuadtree->remove(removedCorner); positionQuadtree->remove(removedCorner); } delete removedCorner; } }
/* A malha deve estar alocada. * */ void MeshIoMsh::readFileMsh(const char* filename, Mesh * mesh) { /* * O que é feito: * * 1) primeiramente lê-se apenas as células (conectividade clássica); * 2) depois são construídos as facet-edges e(ou) facet-faces, lendo-se * os elementos de dimensões menores. * * */ FEPIC_ASSERT(mesh, "invalid mesh pointer", std::invalid_argument); this->fi_registerFile(filename, ".msh"); FILE * file_ptr = fopen(filename, "r"); double coord[3]; int type_tag; char buffer[256]; std::tr1::shared_ptr<Point> p_ptr(new Point()); std::tr1::shared_ptr<Cell> c_ptr(mesh->createCell()); int const spacedim = mesh->spaceDim(); FEPIC_ASSERT(spacedim>0 && spacedim < 4, "mesh has invalid spacedim", std::invalid_argument); long nodes_file_pos; // $Nodes long elems_file_pos; // $Elements // nós nodes_file_pos = find_keyword("$Nodes", 6, file_ptr); //nodes_file_pos++; // only to avoid gcc warning: variable ‘nodes_file_pos’ set but not used [-Wunused-but-set-variable] FEPIC_ASSERT(nodes_file_pos>0, "invalid file format", std::invalid_argument); int num_pts(0); int node_number(0); if ( EOF == fscanf(file_ptr, "%d", &num_pts) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); //mesh->resizePointL(num_pts); //mesh->printInfo(); //std::cout << "DEBUGGGGGGGGGGGGGGGGGGG: "<<mesh << std::endl; //printf("DEBUGGGGGGGGGGGGGGGGGGGGGGGGGGG num_pts=%d; numNodesTotal()=%d; numNodes()=%d\n",num_pts,mesh->numNodesTotal(), mesh->numNodes()); if (NULL == fgets(buffer, sizeof(buffer), file_ptr)) // escapa do \n FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); for (int i=0; i< num_pts; ++i) { if ( NULL == fgets(buffer, sizeof(buffer), file_ptr) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); sscanf(buffer, "%d %lf %lf %lf", &node_number, &coord[0], &coord[1], &coord[2]); FEPIC_ASSERT(node_number==i+1, "wrong file format", std::invalid_argument); p_ptr->setCoord(coord, spacedim); //mesh->getNodePtr(i)->setCoord(coord,spacedim); mesh->pushPoint(p_ptr.get()); } // os pontos não estão completas: falta atribuir os labels // contagem de elementos e alocação elems_file_pos = find_keyword("$Elements", 9, file_ptr); FEPIC_ASSERT(elems_file_pos>0, "invalid file format", std::invalid_argument); int num_cells=0; int num_elms; if (EOF == fscanf(file_ptr, "%d", &num_elms) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); /* --------------------------------------- * Detectando a ordem da malha, verificando sequencia dos elementos, * e contando o número de células. * --------------------------------------- */ const int meshm_cell_msh_tag = mesh->cellMshTag(); if (mshTag2ctype(EMshTag(meshm_cell_msh_tag)) != mesh->cellType()) { //FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); printf("ERROR: ctype2mshTag() = %d\n", ctype2mshTag(mesh->cellType())); printf("ERROR: cell->getMshTag() = %d\n", c_ptr->getMshTag()); throw; } bool wrong_file_err=true; int elem_number; // contagem para verificação de erros. for (int k = 0; k < num_elms; ++k) { if (EOF == fscanf(file_ptr, "%d %d", &elem_number, &type_tag) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); // check sequence if (elem_number != k+1) { wrong_file_err=true; break; } // check type if (type_tag == meshm_cell_msh_tag) { wrong_file_err=false; ++num_cells; } if (!fgets(buffer, sizeof(buffer), file_ptr) || feof(file_ptr)) { wrong_file_err=true; break; } } FEPIC_ASSERT(!wrong_file_err, "Wrong file format. Make sure you created the mesh with correct file format. ", std::invalid_argument); Cell* cell; //cell = Cell::create(mesh->cellType()); /* -------------------------------------- * Lendo as células * -------------------------------------- */ fseek (file_ptr , elems_file_pos , SEEK_SET ); if (EOF == fscanf(file_ptr, "%d", &num_elms) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); this->timer.restart(); int inc(0); int nodes_per_cell = mesh->nodesPerCell(); int id_aux; int numm_tags; int elm_dim; int physical; int const cell_dim = mesh->cellDim(); int const cell_msh_tag = mesh->cellMshTag(); for (int k=0; k < num_elms; ++k) { if ( EOF == fscanf(file_ptr, "%d %d %d %d", &elem_number, &type_tag, &numm_tags, &physical) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); // sincronização FEPIC_ASSERT(elem_number==k+1, "invalid file format", std::invalid_argument); for (int j=1; j<numm_tags; ++j) { if ( EOF == fscanf(file_ptr, "%s", buffer) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); } elm_dim = dimForMshTag(EMshTag(type_tag)); if (elm_dim==0) { if ( EOF == fscanf(file_ptr, "%d", &id_aux) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); --id_aux; mesh->getNodePtr(id_aux)->setTag(physical); } else if (elm_dim == cell_dim) { cell = mesh->pushCell((int*)0); ++inc; FEPIC_ASSERT(cell_msh_tag == type_tag, "Invalid cell or invalid mesh", std::runtime_error); for (int i=0; i< nodes_per_cell; ++i) { if ( EOF == fscanf(file_ptr, "%d", &id_aux) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); cell->setNodeId(i, id_aux-1); } cell->setTag(physical); //mesh->pushCell(cell); } else { if ( NULL == fgets(buffer, sizeof(buffer), file_ptr) ) FEPIC_ASSERT(false, "invalid msh format", std::runtime_error); } }// end for k this->timer.elapsed("readFileMsh(): read connectivity"); // até aqui, apenas foi lido a conectividade // /* constroi as facets e Corners */ if (mesh->qBuildAdjacency()) mesh->buildAdjacency(); else { fclose(file_ptr); return; } /* ___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__ _|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___| */ this->timer.restart(); /* Procura por elementos no contorno que coincidam com as facets. Quando encontrados, * os labels são propagados para as respectivas facet que por sua vez propagam os * labels para seus nós. Os labels só são propagados se eles não foram definidos * nos nós anteriormente. */ fseek (file_ptr , elems_file_pos , SEEK_SET ); fscanf(file_ptr, "%d", &num_elms); int n_nodes = mesh->nodesPerCell(); //int n_vertices_per_facet = mesh->verticesPerFacet(); int n_nodes_per_facet = mesh->nodesPerFacet(); //int n_vertices_per_corner = mesh->verticesPerCorner(); int n_nodes_per_corner = mesh->nodesPerCorner(); int* nodes = new int[n_nodes_per_facet]; // facet nodes //int* vtcs = new int[n_vertices_per_facet]; int* bnodes = new int[n_nodes_per_corner]; // corner nodes //int* bvtcs = new int[n_vertices_per_corner]; int facet_id; int corner_id; for (int k=0; k < num_elms; ++k) { fscanf(file_ptr, "%d %d %d %d", &elem_number, &type_tag, &numm_tags, &physical); //// sincronização //FEPIC_ASSERT(elem_number==k+1, "invalid file format", std::invalid_argument); for (int j=1; j<numm_tags; ++j) { fscanf(file_ptr, "%s", buffer); } elm_dim = dimForMshTag(EMshTag(type_tag)); if ((elm_dim == 0) && (cell_dim!=2)) { fscanf(file_ptr, "%d", &id_aux); } else if (elm_dim == cell_dim-1) // facets { for (int i=0; i<n_nodes_per_facet; ++i) { fscanf(file_ptr, "%d", &nodes[i]); --nodes[i]; if (mesh->getNodePtr(nodes[i])->getTag() == 0) mesh->getNodePtr(nodes[i])->setTag(physical); } //std::copy( nodes, nodes + n_vertices_per_facet, vtcs ); if (cell_dim > 1) { if (mesh->getFacetIdFromVertices(nodes, facet_id)) mesh->getFacetPtr(abs(facet_id))->setTag(physical); //std::cout << (++TESTE) << std::endl; else { printf("WARNING: INVALID FACET IN INPUT MESH! vtcs: "); for (int zz = 0; zz < n_nodes_per_facet; ++zz) printf("%d ", nodes[zz]); printf("\n"); } } } else if (elm_dim == cell_dim-2) // corners { for (int i=0; i<n_nodes_per_corner; ++i) { fscanf(file_ptr, "%d", &bnodes[i]); --bnodes[i]; if (mesh->getNodePtr(bnodes[i])->getTag() == 0) mesh->getNodePtr(bnodes[i])->setTag(physical); } //std::copy( bnodes, bnodes + n_vertices_per_corner, bvtcs ); if (cell_dim>2) { if (mesh->getCornerIdFromVertices(bnodes, corner_id)) { mesh->getCornerPtr(abs(corner_id))->setTag(physical); //std::cout << (++TESTE) << std::endl; } else if (mesh->isVertex(mesh->getNodePtr(bnodes[0])) ) // if is vertex printf("WARNING: INVALID CORNER IN INPUT MESH!\n"); } } else { for (int i=0; i<n_nodes; ++i) { fscanf(file_ptr, "%d", &id_aux); --id_aux; if ((mesh->getNodePtr(id_aux)->getTag()) == 0) mesh->getNodePtr(id_aux)->setTag(physical); } } } this->timer.elapsed("readFileMsh(): search for boundary elements"); if (mesh->cellDim()>2) { const int n_corners_per_facet = mesh->numCornersPerFacet(); // int facetm_facets[n_corners_per_facet]; int *facetm_facets = new int [n_corners_per_facet]; Facet const* facet; Corner* corner; for (int i = 0; i < mesh->numFacetsTotal(); ++i) { facet = mesh->getFacetPtr(i); if (facet->isDisabled()) continue; mesh->getCellPtr(facet->getIncidCell())->getFacetCornersId(facet->getPosition(), facetm_facets); for (int j = 0; j < n_corners_per_facet; ++j) { corner = mesh->getCornerPtr(facetm_facets[j]); if (corner->getTag() == 0) corner->setTag(facet->getTag()); } } delete [] facetm_facets; facetm_facets = NULL; } if (mesh->cellDim()>1) { const int n_cells_total = mesh->numCellsTotal(); Cell * cell; Facet * facet; for (int i = 0; i < n_cells_total; ++i) { cell = mesh->getCellPtr(i); if (cell->isDisabled()) continue; for (int j = 0; j < mesh->numFacetsPerCell(); ++j) { facet = mesh->getFacetPtr(cell->getFacetId(j)); if (facet->getTag() == 0) facet->setTag(cell->getTag()); } } // end loop } // endif fclose(file_ptr); //File.close(); delete [] nodes; //delete [] vtcs; delete [] bnodes; //delete [] bvtcs; mesh->timer.addItems(this->timer); }
/** * Set the corner @a idx by @a c. */ void ForcePlatform::SetCorner(int idx, const Corner& c) { this->SetCorner(idx,c.x(),c.y(),c.z()); };
void World::set_tera_height(Plasma &plasma) { memset(corner_matrix, 0, sizeof(Corner)*(max_x_loc+1)*(max_y_loc+1)); // short seaHeight = TerrainRes::max_height(TERRAIN_OCEAN); short seaHeight = 0; // no more sea int y; int x; for(y = 0; y <= max_y_loc; ++y ) { for(x = 0; x <= max_x_loc; ++x) { Corner *cornerPtr = get_corner(x,y); cornerPtr->set_altitude(plasma.get_pix(x,y)); cornerPtr->set_sea_altitude(seaHeight); // set gradient_x float gradientX; if(x <= 0) { err_when(x < 0); gradientX = float(4*plasma.get_pix(x+1,y) - plasma.get_pix(x+2,y) - 3*plasma.get_pix(x,y)) / (2 * LOCATE_WIDTH); } else if( x >= max_x_loc ) { err_when(x > max_x_loc); gradientX = float(plasma.get_pix(x-2,y) - 4*plasma.get_pix(x-1,y) + 3*plasma.get_pix(x,y)) / (2 * LOCATE_WIDTH); } else { gradientX = float(plasma.get_pix(x+1,y) - plasma.get_pix(x-1,y)) / (2 * LOCATE_WIDTH); } // if( gradientX >= 0.0f && gradientX <= 0.25f ) // gradientX += 0.15f; // else if( gradientX < 0.0f && gradientX >= -0.25f ) // gradientX -= 0.15f; cornerPtr->set_gradient_x( gradientX ); // set gradient_y float gradientY; if(y <= 0) { err_when(y < 0); gradientY = float(4*plasma.get_pix(x,y+1) - plasma.get_pix(x,y+2) - 3*plasma.get_pix(x,y)) / (2 * LOCATE_HEIGHT); } else if( y >= max_y_loc ) { err_when(y > max_y_loc); gradientY = float(plasma.get_pix(x,y-2) - 4*plasma.get_pix(x,y-1) + 3*plasma.get_pix(x,y)) / (2 * LOCATE_HEIGHT); } else { gradientY = float(plasma.get_pix(x,y+1) - plasma.get_pix(x,y-1)) / (2 * LOCATE_HEIGHT); } // if( gradientY >= 0.0f && gradientY <= 0.25f ) // gradientY += 0.15f; // else if( gradientY < 0.0f && gradientY >= -0.25f ) // gradientY -= 0.15f; cornerPtr->set_gradient_y( gradientY ); } } // calculate polynomial coefficient for(y = 0; y < max_y_loc; ++y ) { for(x = 0; x < max_x_loc; ++x) { LocationCorners lc; get_loc_corner(x,y, &lc); short &z0 = lc.top_left->altitude; short &z1 = lc.top_right->altitude; short &z2 = lc.bottom_left->altitude; short &z3 = lc.bottom_right->altitude; short &duz0w = lc.top_left->gradient_x; // du/dz * LOCATE_WIDTH short &dvz0h = lc.top_left->gradient_y; short &duz1w = lc.top_right->gradient_x; short &dvz1h = lc.top_right->gradient_y; short &duz2w = lc.bottom_left->gradient_x; short &dvz2h = lc.bottom_left->gradient_y; short &duz3w = lc.bottom_right->gradient_x; short &dvz3h = lc.bottom_right->gradient_y; lc.loc_ptr->c30 = (duz1w + duz0w - (z1-z0) * 2) << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT); lc.loc_ptr->c21 = (duz3w + duz0w - duz1w - duz2w) << (C_MULTIPLIER_SHIFT - 1 - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_HEIGHT_SHIFT); lc.loc_ptr->c12 = (dvz3h + dvz0h - dvz1h - dvz2h) << (C_MULTIPLIER_SHIFT - 1 - LOCATE_WIDTH_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT); lc.loc_ptr->c03 = (dvz2h + dvz0h - (z2-z0) * 2) << (C_MULTIPLIER_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT); lc.loc_ptr->c20 = ( (z1-z0) * 3 - duz1w - duz0w * 2 ) << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_WIDTH_SHIFT); lc.loc_ptr->c11 = (( z3 + z0 - z1 - z2 ) << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT - LOCATE_HEIGHT_SHIFT)) - (lc.loc_ptr->c21 << LOCATE_WIDTH_SHIFT) - (lc.loc_ptr->c12 << LOCATE_HEIGHT_SHIFT); lc.loc_ptr->c02 = ( (z2-z0) * 3 - dvz2h - dvz0h * 2 ) << (C_MULTIPLIER_SHIFT - LOCATE_HEIGHT_SHIFT - LOCATE_HEIGHT_SHIFT); lc.loc_ptr->c00 = z0 << C_MULTIPLIER_SHIFT; lc.loc_ptr->c10 = duz0w << (C_MULTIPLIER_SHIFT - LOCATE_WIDTH_SHIFT); lc.loc_ptr->c01 = dvz0h << (C_MULTIPLIER_SHIFT - LOCATE_HEIGHT_SHIFT); // find the height of the rendered bitmap { lc.loc_ptr->min_y = 0; lc.loc_ptr->max_y = 0; int seaLevel = 0; if( lc.top_left->is_sea() ) seaLevel = lc.top_left->sea_altitude; if( lc.top_right->is_sea() ) seaLevel = lc.top_right->sea_altitude; if( lc.bottom_left->is_sea() ) seaLevel = lc.bottom_left->sea_altitude; if( lc.bottom_right->is_sea() ) seaLevel = lc.bottom_right->sea_altitude; if( seaLevel ) lc.loc_ptr->loc_flag |= LOCATE_SEA_COAST; else lc.loc_ptr->loc_flag &= ~LOCATE_SEA_COAST; // height relative to top left corner // int refHeight = ZoomMatrix::calc_abs_y(0, 0, lc.loc_ptr->evaluate_z(0, 0)); int refHeight = ZoomMatrix::calc_abs_y(0, 0, lc.loc_ptr->c00 >> C_MULTIPLIER_SHIFT); // include LOCATE_WIDTH, LOCATE_HEIGHT for wider min_y, max_y for(int v = 0; v <= LOCATE_HEIGHT; v+=LOCATE_HEIGHT/4 ) { for( int u = 0; u <= LOCATE_WIDTH; u+=LOCATE_WIDTH/4 ) { long z = lc.loc_ptr->evaluate_z(u, v); // if cover by sea if( seaLevel && z < seaLevel ) z = seaLevel; int pointY = ZoomMatrix::calc_abs_y(u, v, z) - refHeight; //(z - z0) * ZOOM_Z_HEIGHT //+ (u * ZOOM_LOC_X_HEIGHT * LOCATE_HEIGHT //+ v * ZOOM_LOC_Y_HEIGHT * LOCATE_WIDTH ) //>> (LOCATE_WIDTH_SHIFT + LOCATE_HEIGHT_SHIFT); if( pointY < lc.loc_ptr->min_y) lc.loc_ptr->min_y = pointY; if( pointY > lc.loc_ptr->max_y) lc.loc_ptr->max_y = pointY; } } lc.loc_ptr->min_y -= 8; // -4 for more space lc.loc_ptr->max_y += 8; // +4 for more space } } } }
bool CornerSequence::placeMacrosWithIncrementalUpdate(int startPosition, int backupPosition) { bool placedUnsuccessfully = false; // Store Corners removed from sizeQuadtree during finding valid Corners. std::vector<Corner *> *temporarilyRemovedCorners = new std::vector<Corner *>(); for (int i = startPosition; i < macros->size(); ++i) { //std::cout << i << "\n"; Macro *macro = macros->at(i); macro->setOrientation(orientations->at(i)); int macroWidth = macro->getWidth(); int macroHeight = macro->getHeight(); Corner *corner = corners->at(i); //std::cout << "begin Macro " << i << "\n"; //std::cout << "smallest width emtpy Tile: "; //cornerHorizontalTilePlane->getEmptyTileWithSmallestWidth()->print(); //std::cout << "smallest height empty Tile: "; //cornerVerticalTilePlane->getEmptyTileWithSmallestHeight()->print(); //std::cout << "smallest width Macro: "; //////(*widthSortedMacros->begin())->print(); //widthSortedMacros->getSmallest()->print(); //std::cout << "smallest height Macro: "; ////(*heightSortedMacros->begin())->print(); //heightSortedMacros->getSmallest()->print(); //fillInWastedRegion(); // Check whether to select another Corner. bool toSelectAnotherCorner = false; if (corner == 0) { toSelectAnotherCorner = true; } else if (corner->isNotFromTilePlane()) { Corner *inputCorner = corner; std::vector<Point *> *foundCorners = positionQuadtree->getPointsAtXY(inputCorner->getX(), inputCorner->getY()); if (foundCorners == 0) { // No matched Corner is found. toSelectAnotherCorner = true; } else { for (int j = 0; j < foundCorners->size(); ++j) { Corner *foundCorner = static_cast<Corner *>(foundCorners->at(j)); if (foundCorner->getDirection() == inputCorner->getDirection()) { // The matched Corner is found. corner = foundCorner; break; } // No matched Corner is found. toSelectAnotherCorner = true; } delete foundCorners; } delete inputCorner; corners->at(i) = 0; // If macro ends up being unsuccessfully placed, // notFromTilePlane Corners after corner will be deleted in ~CornerSeqence(). } if (toSelectAnotherCorner) { corner = static_cast<Corner *>(sizeQuadtree->getPointRandomlyByXY(macroWidth, macroHeight, true, true)); if (corner == 0) { // No Corner is available. placedUnsuccessfully = true; indexPlacedUnsuccessfully = i; break; } } // Check overlap. int cornerDirection; int macroXStart; int macroYStart; int macroXEnd; int macroYEnd; int cornerX; int cornerY; while (true) { // Check corner gap size. bool cornerGapSizeIsValid = true; if (corner->isType1()) { if (corner->isGapOnHorizontalSide()) { if (corner->getGapSize() >= macroWidth) { cornerGapSizeIsValid = false; } } else { if (corner->getGapSize() >= macroHeight) { cornerGapSizeIsValid = false; } } } if (cornerGapSizeIsValid) { // Calculate macro position. cornerX = corner->getX(); cornerY = corner->getY(); cornerDirection = corner->getDirection(); switch (cornerDirection) { case 0: // Bl macroXStart = cornerX; macroYStart = cornerY; macroXEnd = cornerX + macroWidth; macroYEnd = cornerY + macroHeight; break; case 1: // Br macroXStart = cornerX - macroWidth; macroYStart = cornerY; macroXEnd = cornerX; macroYEnd = cornerY + macroHeight; break; case 2: // Tl macroXStart = cornerX; macroYStart = cornerY - macroHeight; macroXEnd = cornerX + macroWidth; macroYEnd = cornerY; break; case 3: // Tr macroXStart = cornerX - macroWidth; macroYStart = cornerY - macroHeight; macroXEnd = cornerX; macroYEnd = cornerY; break; } // Check overlap. if (cornerDirection <= 1) { if (cornerHorizontalTilePlane->checkAreaEmptyCheckFromBottom( macroXStart, macroYStart, macroXEnd, macroYEnd, corner->getHorizontalTile())) { // Does not overlap. break; } } else { if (cornerHorizontalTilePlane->checkAreaEmptyCheckFromTop( macroXStart, macroYStart, macroXEnd, macroYEnd, corner->getHorizontalTile())) { // Does not overlap. break; } } } // corner is not valid. // Select another Corner. sizeQuadtree->remove(corner); temporarilyRemovedCorners->push_back(corner); corner = static_cast<Corner *>(sizeQuadtree->getPointRandomlyByXY(macroWidth, macroHeight, true, true)); if (corner == 0) { // No Corner is available. placedUnsuccessfully = true; indexPlacedUnsuccessfully = i; break; } } if (placedUnsuccessfully) { break; } // A valid Corner is selected. // Insert removed Corners back to quadtrees. for (int j = 0; j < temporarilyRemovedCorners->size(); ++j) { sizeQuadtree->insert(temporarilyRemovedCorners->at(j)); } temporarilyRemovedCorners->clear(); // Copy the valid Corner and replace corners->at(i) // because the valid Corner will be deleted after macro is placed. corners->at(i) = corner->copyAsNotFromTilePlane(); // Place macro at corner. macro->setXStart(macroXStart); macro->setYStart(macroYStart); macro->updateRectanglesPosition(); Tile *horizontalTile = new Tile(macroXStart, macroYStart, macroXEnd, macroYEnd, true); Tile *verticalTile = new Tile(macroXStart, macroYStart, macroXEnd, macroYEnd, true); Tile *startHorizontalTile; Tile *startVerticalTile; switch (cornerDirection) { case 0: // Bl startHorizontalTile = corner->getHorizontalTile(); startVerticalTile = corner->getVerticalTile(); break; case 1: // Br startHorizontalTile = corner->getHorizontalTile(); startVerticalTile = cornerVerticalTilePlane->findTile(macroXStart, macroYStart, corner->getVerticalTile()); break; case 2: // Tl startHorizontalTile = cornerHorizontalTilePlane->findTile(macroXStart, macroYStart, corner->getHorizontalTile()); startVerticalTile = corner->getVerticalTile(); break; case 3: // Tr startHorizontalTile = cornerHorizontalTilePlane->findTile(macroXStart, macroYStart, corner->getHorizontalTile()); startVerticalTile = cornerVerticalTilePlane->findTile(macroXStart, macroYStart, corner->getVerticalTile()); break; } cornerHorizontalTilePlane->placeSolidTileGivenBothStartTiles(horizontalTile, startHorizontalTile, startVerticalTile); startHorizontalTile = horizontalTile; //switch (cornerDirection) { //case 0: // // Bl // startVerticalTile = corner->getVerticalTile(); // break; //case 1: // // Br // startVerticalTile = cornerVerticalTilePlane->findTile(macroXStart, macroYStart, corner->getVerticalTile()); // break; //case 2: // // Tl // startVerticalTile = corner->getVerticalTile(); // break; //case 3: // // Tr // startVerticalTile = cornerVerticalTilePlane->findTile(macroXStart, macroYStart, corner->getVerticalTile()); // break; //} cornerVerticalTilePlane->placeSolidTileGivenBothStartTiles(verticalTile, startVerticalTile, startHorizontalTile); // Remove macro from sets. //widthSortedMacros->erase(macro); //heightSortedMacros->erase(macro); // Calculate Corners' width and height. cornerHorizontalTilePlane->calculateCurrentCornersWidthAndHeight(); cornerVerticalTilePlane->calculateCurrentCornersWidthAndHeight(); // Update quadtrees. updateQuadtrees(); } delete temporarilyRemovedCorners; return !placedUnsuccessfully; }
void TilePlaneView::display() { std::vector<Tile *> *tiles = tilePlane->collectAllTiles(); for (int i = 0; i < tiles->size(); ++i) { Tile *tile = tiles->at(i); int tileXStart = tile->getXStart(); int tileYStart = tile->getYStart(); int tileXEnd = tile->getXEnd(); int tileYEnd = tile->getYEnd(); if (tile->isSolid()) { window->drawRectangle(tileXStart, tileYStart, tileXEnd, tileYEnd, 0.5, 0.5, 1, 0.8, 0.8, 0.8); } else { window->drawRectangle(tileXStart, tileYStart, tileXEnd, tileYEnd, 0.2, 0.2, 0.2, 0.8, 0.8, 0.8); } // Draw Corners if (tile->isEmpty()) { Corner *blCorner = tile->getBlCorner(); Corner *brCorner = tile->getBrCorner(); Corner *tlCorner = tile->getTlCorner(); Corner *trCorner = tile->getTrCorner(); if (blCorner != 0) { if (blCorner->isType0()) { window->drawRectangle(tileXStart + 1, tileYStart + 1, tileXStart + 2, tileYStart + 2, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, true); } else { window->drawRectangle(tileXStart + 1, tileYStart + 1, tileXStart + 2, tileYStart + 2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5); } } if (brCorner != 0) { if (brCorner->isType0()) { window->drawRectangle(tileXEnd - 2, tileYStart + 1, tileXEnd - 1, tileYStart + 2, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, true); } else { window->drawRectangle(tileXEnd - 2, tileYStart + 1, tileXEnd - 1, tileYStart + 2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5); } } if (tlCorner != 0) { if (tlCorner->isType0()) { window->drawRectangle(tileXStart + 1, tileYEnd - 2, tileXStart + 2, tileYEnd - 1, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, true); } else { window->drawRectangle(tileXStart + 1, tileYEnd - 2, tileXStart + 2, tileYEnd - 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5); } } if (trCorner != 0) { if (trCorner->isType0()) { window->drawRectangle(tileXEnd - 2, tileYEnd - 2, tileXEnd - 1, tileYEnd - 1, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, true); } else { window->drawRectangle(tileXEnd - 2, tileYEnd - 2, tileXEnd - 1, tileYEnd - 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5); } } } } delete tiles; }
//---------- Begin of function MapMatrix::draw_map ------------// // see also World::explore // void MapMatrix::draw_map() { //----------- draw map now ------------// sys.yield(); short fireColor = vga_back.translate_color(FIRE_COLOR); short plantColor = vga_back.translate_color(plant_res.plant_map_color); short seaColor = vga_back.translate_color(0x32); short rockColor = vga_back.translate_color( 0x59 ); short mapModeColor = vga_back.translate_color( VGA_GRAY+10 ); short unexploredColor = vga_back.translate_color(UNEXPLORED_COLOR); short shadowColor = vga_back.translate_color( VGA_GRAY+2 ); short roadColor = vga_back.translate_color( VGA_GRAY+12 ); short nationColorArray[MAX_NATION+2]; for( int n = 0; n < MAX_NATION+2; ++n ) nationColorArray[n] = vga_back.translate_color(nation_array.nation_power_color_array[n]); // #### begin Ban 8/12 #######// int temp3 = vga_back.buf_true_pitch() -2; short *temp6 = vga_back.buf_ptr((image_x1 + image_x2)/2, image_y1); #ifdef ASM_FOR_MSVC _asm { MOV AX , DS MOV ES , AX MOV EDX, temp3 MOV EDI, temp6 CLD MOV AX, word ptr UNEXPLORED_COLOR MOV CX, AX // processing the color for drawing SHL EAX, 16 MOV AX, CX MOV EBX, 100 XOR ECX, ECX PutLineUpper: // draw upper triangle INC ECX REP STOSD MOV ECX, 101 // restore ECX after STOSD for updating EDI SUB ECX, EBX ADD EDI, EDX // updating EDI to start point of next line SUB EDI, ECX SUB EDI, ECX SUB EDI, ECX SUB EDI, ECX DEC EBX // decrease the remain height JNZ PutLineUpper // loop MOV EBX, 99 // ready parameters for drawing lower triangle ADD EDX, 4 ADD EDI, 4 PutLineLower: // draw lower triangle MOV ECX, EBX REP STOSD ADD EDI, EDX // updating EDI to start point of next line SUB EDI, EBX SUB EDI, EBX SUB EDI, EBX SUB EDI, EBX DEC EBX // decrease the remain height JNZ PutLineLower // loop } #else int lineDiff = temp3 / 2; int lineLength = 2; // Blacken upper half of minimap. for ( int i = 0; i < 100; ++i ) { for ( int j = 0; j < lineLength; ++j ) { *temp6 = UNEXPLORED_COLOR; ++temp6; } temp6 += lineDiff - lineLength; lineLength += 2; } // Blacken lower half of minimap. lineLength = 99 * 2; lineDiff += 2; temp6 += 2; for ( int i = 0; i < 99; ++i ) { for ( int j = 0; j < lineLength; ++j ) { *temp6 = UNEXPLORED_COLOR; ++temp6; } temp6 += lineDiff - lineLength; lineLength -= 2; } #endif // #### end Ban 8/12 #######// // { // traversal of location in MapMatrix // int pixelX = (image_x1 + image_x2 + 1) / 2; // int pixelY = image_y1; // int xLoc, yLoc; // int writePtrInc = vga_back.buf_pitch() + 1; // for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc ) // { // short* writePtr = vga_back.buf_ptr(pixelX, pixelY); // xLoc = 0; // Location *locPtr = get_loc( xLoc, yLoc ); // for( xLoc = 0; xLoc < max_x_loc; (xLoc += 2), (writePtr += writePtrInc), (locPtr+=2) ) // { // } // } // } switch(map_mode) { case MAP_MODE_TERRAIN: { int pixelX = (image_x1 + image_x2 + 1) / 2; int pixelY = image_y1; int xLoc, yLoc; int writePtrInc = vga_back.buf_pitch() + 1; for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc ) { short* writePtr = vga_back.buf_ptr(pixelX, pixelY); int tileYOffset = (yLoc & TERRAIN_TILE_Y_MASK) * TERRAIN_TILE_WIDTH; xLoc = 0; Location* locPtr = get_loc( xLoc, yLoc ); for( ; xLoc < max_x_loc; (xLoc += 2), (locPtr += 2), (writePtr += writePtrInc) ) { if( locPtr->explored() ) { // ##### begin Gilbert 10/2 #######// if( filter_object_flag || filter_nation_flag ) // do not anything except filtered objects when filters are on *writePtr = mapModeColor; else if( locPtr->fire_str() > 0) // ##### end Gilbert 10/2 #######// *writePtr = fireColor; else if( locPtr->is_plant() || xLoc+1<max_x_loc && locPtr[1].is_plant() ) *writePtr = plantColor; else if( locPtr->is_rock() ) *writePtr = rockColor; else if( locPtr->has_dirt() ) { Rock *dirtPtr = dirt_array[locPtr->dirt_recno()]; RockInfo *dirtInfo = rock_res.get_rock_info(dirtPtr->rock_recno); if (dirtInfo->rock_type == 'P') *writePtr = seaColor; else *writePtr = rockColor; } else if( locPtr->is_road() ) *writePtr = vga_back.translate_color(terrain_res.get_map_tile(locPtr->road_terrain_id)[tileYOffset + (xLoc & TERRAIN_TILE_X_MASK)]); else { if( xLoc < 2 || terrain_res[locPtr->terrain_id]->average_type >= terrain_res[(locPtr-2)->terrain_id]->average_type ) { // get terrain pixel from terrain_res *writePtr = vga_back.translate_color(terrain_res.get_map_tile(locPtr->terrain_id)[tileYOffset + (xLoc & TERRAIN_TILE_X_MASK)]); } else { *writePtr = shadowColor; } } } //else // not needed because filled black already //{ // *writePtr = unexploredColor; //} } } } break; // ##### begin Gilbert 2/11 #####// case MAP_MODE_TRADE: // ##### end Gilbert 2/11 #####// case MAP_MODE_SPOT: { // traversal of location in MapMatrix int pixelX = (image_x1 + image_x2 + 1) / 2; int pixelY = image_y1; int xLoc, yLoc; int writePtrInc = vga_back.buf_pitch() + 1; for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc ) { short* writePtr = vga_back.buf_ptr(pixelX, pixelY); xLoc = 0; Location* locPtr = get_loc( xLoc, yLoc ); for( ; xLoc < max_x_loc; (xLoc += 2), (locPtr +=2), (writePtr += writePtrInc) ) { if( locPtr->explored() ) { *writePtr = mapModeColor; } } } } break; case MAP_MODE_POWER: { int pixelX = (image_x1 + image_x2 + 1) / 2; int pixelY = image_y1; int xLoc, yLoc; int writePtrInc = vga_back.buf_pitch() + 1; for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc ) { short* writePtr = vga_back.buf_ptr(pixelX, pixelY); xLoc = 0; Location *locPtr = get_loc( xLoc, yLoc ); for( xLoc = 0; xLoc < max_x_loc; (xLoc += 2), (locPtr +=2), (writePtr += writePtrInc) ) { if( locPtr->explored() ) { // ####### begin Gilbert 10/2 #########// if( filter_object_flag || filter_nation_flag ) // do not anything except filtered objects when filters are on *writePtr = mapModeColor; else if( locPtr->sailable() ) // ####### end Gilbert 10/2 #########// *writePtr = seaColor; else if( locPtr->is_rock() || locPtr[1].is_rock() ) *writePtr = rockColor; /* else if( locPtr->has_dirt() ) { Rock *dirtPtr = dirt_array[locPtr->dirt_recno()]; RockInfo *dirtInfo = rock_res.get_rock_info(dirtPtr->rock_recno); if (dirtInfo->rock_type == 'P') *writePtr = seaColor; else *writePtr = rockColor; } else if( locPtr->is_plant() || xLoc+1<max_x_loc && locPtr[1].is_plant() ) *writePtr = plantColor; */ else // ###### begin Gilbert 21/12 ########// { if( power_mode ) *writePtr = nationColorArray[locPtr->power_nation_recno]; else *writePtr = nationColorArray[0]; } // ###### end Gilbert 21/12 ########// } } } } break; case MAP_MODE_ALTITUDE: { int pixelX = (image_x1 + image_x2 + 1) / 2; int pixelY = image_y1; int xLoc, yLoc; int writePtrInc = vga_back.buf_pitch() + 1; for( yLoc = 0; yLoc < max_y_loc; (yLoc&1?++pixelY:--pixelX) , ++yLoc ) { short* writePtr = vga_back.buf_ptr(pixelX, pixelY); xLoc = 0; for( xLoc = 0; xLoc < max_x_loc; (xLoc += 2), (writePtr += writePtrInc) ) { Corner *cornerPtr = get_corner( xLoc, yLoc ); short alt = cornerPtr->get_altitude(); if( alt > 255 ) alt = 255; else if( alt < 0 ) alt = 0; *writePtr = vga.make_pixel((BYTE)alt, 128, 32); } } } break; } sys.yield(); }