SparseMatrix<float> createInteractionMatrix(int dim){ std::vector<MatrixElement<float>> elems; int nCells = dim * dim; for (int i = 0; i < nCells; ++i){ //In the matrix all diagonal entires are 4 and neighbor cells are -1 elems.push_back(MatrixElement<float>(i, i, 4)); int x, y; cellPos(i, x, y, dim); elems.push_back(MatrixElement<float>(i, cellNumber(x - 1, y, dim), -1)); elems.push_back(MatrixElement<float>(i, cellNumber(x + 1, y, dim), -1)); elems.push_back(MatrixElement<float>(i, cellNumber(x, y - 1, dim), -1)); elems.push_back(MatrixElement<float>(i, cellNumber(x, y + 1, dim), -1)); } return SparseMatrix<float>(elems, dim, true); }
SparseMatrix SimpleFluid::generateMatrix(){ std::vector<Element> elements; int cells = std::pow(dim, 2); //All diagonal entries of the matrix are 4 for (int i = 0; i < cells; ++i){ elements.push_back(Element(i, i, 4)); //Set the cell-cell interaction values for the cells up/down/left/right of our cell //note that this simulation is currently using wrapping boundaries so we just wrap edges //in cellNumber int x, y; cellPos(i, x, y); elements.push_back(Element(i, cellNumber(x - 1, y), -1)); elements.push_back(Element(i, cellNumber(x + 1, y), -1)); elements.push_back(Element(i, cellNumber(x, y - 1), -1)); elements.push_back(Element(i, cellNumber(x, y + 1), -1)); } return SparseMatrix(elements, dim, true); }
void SimpleTable::TableDrawCell ( JPainter& p, const JPoint& cell, const JRect& rect ) { // Convert the row number into a JString. JString cellNumber(cell.y); // Draw the JString that holds the value. p.String(rect, cellNumber, JPainter::kHAlignLeft, JPainter::kVAlignTop); }
void DataTable::TableDrawCell ( JPainter& p, const JPoint& cell, const JRect& rect ) { // Convert the array's current element into a JString. JString cellNumber(itsData->GetElement(cell.y)); // Draw the JString that holds the value. p.String(rect, cellNumber, JPainter::kHAlignLeft, JPainter::kVAlignTop); }
void SelectionTable::TableDrawCell ( JPainter& p, const JPoint& cell, const JRect& rect ) { // JTable keeps track of what's selected. If we want just // basic hilighting of the selected cells, we can have JTable // do it with this call: HilightIfSelected(p, cell, rect); // Convert the array's current element into a JString. JString cellNumber(itsData->GetElement(cell.y)); // Draw the JString that holds the value. p.String(rect, cellNumber, JPainter::kHAlignLeft, JPainter::kVAlignTop); }