Exemplo n.º 1
0
int main(int narg, char** args) {
  if(narg != 3) {
    std::cout << "usage: generate_palettes <width> <height>" << std::endl;
    return 0;
  } // if

  int width = std::atoi(args[1]);
  int height = std::atoi(args[2]);

  double start = 0.0, end = 1.0;
  double step = (end - start) / height;

  double value = start;
  std::ofstream fdata("palette_data.dat");
  for(int y = 0; y < height; ++ y) {
    for(int x = 0; x < width; ++ x) {
      fdata << value << "\t";
    } // for
    fdata << std::endl;
    value += step;
  } // for
  fdata.close();

  return 0;
} // main()
Exemplo n.º 2
0
common::Error Http2Client::send_error(common::http::http_protocols protocol,
                                      common::http::http_status status,
                                      const char* extra_header,
                                      const char* text,
                                      bool is_keep_alive,
                                      const HttpServerInfo& info) {
  if (is_http2() && protocol == common::http::HP_2_0) {
    const std::string title = common::ConvertToString(status);
    char err_data[1024] = {0};
    off_t err_len = common::SNPrintf(err_data, sizeof(err_data), HTML_PATTERN_ISISSSS7, status,
                                     title, status, title, text, info.server_url, info.server_name);
    common::Error err = send_headers(protocol, status, extra_header, "text/html", &err_len, nullptr,
                                     is_keep_alive, info);
    if (err && err->isError()) {
      DEBUG_MSG_ERROR(err);
      return err;
    }

    StreamSPtr header_stream = findStreamByType(common::http2::HTTP2_HEADERS);
    if (!header_stream) {
      return DEBUG_MSG_PERROR("findStreamByType", EAGAIN);
    }

    common::http2::frame_hdr hdr = common::http2::frame_data::create_frame_header(
        common::http2::HTTP2_FLAG_END_STREAM, header_stream->sid(), err_len);
    common::http2::frame_data fdata(hdr, err_data);
    return header_stream->sendFrame(fdata);
  }

  return HttpClient::send_error(protocol, status, extra_header, text, is_keep_alive, info);
}
Exemplo n.º 3
0
void SelectMouseMode::OnMouseButtonEvent(Viewport *vp, uint8 state)
{
	this->mouse_state = state & MB_CURRENT;
	if (this->mouse_state != 0) {
		FinderData fdata(CS_RIDE | CS_PERSON, false);
		switch (vp->ComputeCursorPosition(&fdata)) {
			case CS_RIDE: {
				RideInstance *ri = _rides_manager.GetRideInstance(fdata.ride);
				if (ri == nullptr) break;
				switch (ri->GetKind()) {
					case RTK_SHOP:
						ShowShopManagementGui(fdata.ride);
						break;

					case RTK_COASTER:
						ShowCoasterManagementGui(ri);
						break;

					default: break; // Other types are not implemented yet.
				}
				break;
			}

			case CS_PERSON:
				ShowGuestInfoGui(fdata.person);
				break;

			default: break;
		}
	}
}
Exemplo n.º 4
0
static void compare_with_file(const void *buf, size_t len, const char *fn)
{
  osm2go_platform::MappedFile fdata(fn);

  assert(fdata);
  assert_cmpnum(fdata.length(), len);

  assert_cmpmem(fdata.data(), fdata.length(), buf, len);
}
Exemplo n.º 5
0
void PathBuildManager::OnMouseButtonEvent(Viewport *vp, uint8 state)
{
	this->mouse_state = state & MB_CURRENT;

	if ((this->mouse_state & MB_LEFT) != 0) { // Left-click -> select current tile.
		if (this->state == PBS_LONG_BUILD || this->state == PBS_LONG_BUY) {
			this->ConfirmLongPath();
		} else {
			FinderData fdata((CS_GROUND | CS_PATH), FW_TILE);
			if (vp->ComputeCursorPosition(&fdata) != CS_NONE) this->TileClicked(fdata.voxel_pos);
		}
	} else if ((this->mouse_state & MB_RIGHT) != 0 && this->state == PBS_SINGLE) {
		FinderData fdata(CS_PATH, FW_TILE);
		if (vp->ComputeCursorPosition(&fdata) != CS_NONE && RemovePath(fdata.voxel_pos, false)) {
			_additions.Commit();
		}
	}
}
Exemplo n.º 6
0
void RateStateSimWindow::recalc(void) {
	std::vector<std::vector<realtype> >	results;
	double					time_max = 200, time_step = 0.01;
	RSParams				params(NBLOCKS, NEQ, NPARAMS, time_step, time_max);
	unsigned int			i, npoints;
	double					xi, vi, hi;
	
	std::cerr << param_a << " " << param_b << " " << param_k << " " << param_r << " " << param_w << std::endl;
	for (i=0;i<params.num_blocks();++i) {
		params.param(i, A_PARAM) = RCONST(param_a);
		params.param(i, B_PARAM) = RCONST(param_b);
		params.param(i, K_PARAM) = RCONST(param_k);
		params.param(i, R_PARAM) = RCONST(param_r);
		params.param(i, W_PARAM) = RCONST(param_w);
		params.init_val(i, EQ_X) = RCONST(-10.0);
		params.init_val(i, EQ_V) = RCONST(1.0);
		params.init_val(i, EQ_H) = RCONST(1.0);
	}
	
	run_rate_state_sim(results, params);
	npoints = results.size();
	QVector<QPointF>		xdata(npoints), vdata(npoints), hdata(npoints), fdata(npoints), dp_data(npoints);
	double force_integral=0, old_t=0;
	
	for (i=0;i<results.size();++i) {
		xi = results[i][1];
		vi = results[i][2];
		hi = results[i][3];
		xdata[i] = QPointF(results[i][0], xi);
		vdata[i] = QPointF(results[i][0], vi);
		hdata[i] = QPointF(results[i][0], hi);
		fdata[i] = QPointF(results[i][0], F(0, vi, hi, params));
		dp_data[i] = QPointF(results[i][0], results[i][0]);
		force_integral += (results[i][0]-old_t)*F(0, vi, hi, params);
		old_t = results[i][0];
	}
	force_integral /= (results.size()/(time_step*time_max));
	
	//std::cerr << force_integral << std::endl;
	
	position_data->setData(new QwtPointSeriesData(xdata));
	velocity_data->setData(new QwtPointSeriesData(vdata));
	theta_data->setData(new QwtPointSeriesData(hdata));
	force_data->setData(new QwtPointSeriesData(fdata));
	driver_data->setData(new QwtPointSeriesData(dp_data));
	
	position_plot->replot();
	velocity_plot->replot();
	theta_plot->replot();
	force_plot->replot();
}
Exemplo n.º 7
0
void PathBuildManager::OnMouseMoveEvent(Viewport *vp, const Point16 &old_pos, const Point16 &pos)
{
	if (this->state == PBS_LONG_BUILD) {
		this->ComputeNewLongPath(vp->ComputeHorizontalTranslation(vp->rect.width / 2 - pos.x, vp->rect.height / 2 - pos.y));
	} else if ((this->mouse_state & MB_RIGHT) != 0) {
		/* Drag the window if button is pressed down. */
		vp->MoveViewport(pos.x - old_pos.x, pos.y - old_pos.y);
	} else if ((this->mouse_state & MB_LEFT) != 0 && this->state == PBS_SINGLE) {
		/* Continue adding paths (click and drag). */
		FinderData fdata((CS_GROUND | CS_PATH), FW_TILE);
		if (vp->ComputeCursorPosition(&fdata) != CS_NONE) {
			vp->tile_cursor.SetCursor(fdata.voxel_pos, fdata.cursor);
			this->TileClicked(fdata.voxel_pos);
		}
	} else {
		/* Only update tile cursor if no tile selected yet. */
		if (this->state == PBS_SINGLE || this->state == PBS_WAIT_VOXEL) {
			FinderData fdata((CS_GROUND | CS_PATH), FW_TILE);
			if (vp->ComputeCursorPosition(&fdata) != CS_NONE) {
				vp->tile_cursor.SetCursor(fdata.voxel_pos, fdata.cursor);
			}
		}
	}
}
Exemplo n.º 8
0
// Save item map into given file. 
bool DataSet::saveItemMap(string fname) {
  ofstream fdata(fname.c_str());
  if(!fdata) {
   cerr << "Error opening file to save map data" << endl; 
   return false;
  }
  for(int i = 0; i < numTrans; i++){
    for(int j = 0; j < g; j++){
      fdata << d_sets[i][j].getGroup() << " " 
	    << d_sets[i][j].getId();
      if(j < g-1) {
	fdata << ",";
      }
    }
    fdata << endl; 
  }
  fdata.close();
}
Exemplo n.º 9
0
// Save frequent itemsets into given file.
bool DataSet::saveFreqItemSets(string fname) {
  ofstream fdata(fname.c_str());
  // Check if open file successful.
  if(!fdata) {
   cerr << "Error opening file to save map data" << endl; 
   return false;
  }
  map<Itemset, int>::iterator it; 
  for(it = freqsets.begin(); it != freqsets.end(); it++) {
    float support = (float)(*it).second/numTrans; 
    if(support > minSupport) {
      fdata << it->first << ":" << support << endl; 
    } else {
      freqsets.erase(it->first);
    }
  }

  fdata.close();
  return true;
}
Exemplo n.º 10
0
void FenceGui::SelectorMouseMoveEvent(Viewport *vp, const Point16 &pos)
{
	if (this->fence_type == FENCE_TYPE_INVALID || this->selector == nullptr) return;

	FinderData fdata(CS_GROUND_EDGE, FW_EDGE);
	if (vp->ComputeCursorPosition(&fdata) != CS_GROUND_EDGE) return;
	if (fdata.cursor < CUR_TYPE_EDGE_NE || fdata.cursor > CUR_TYPE_EDGE_NW) return;

	if (_game_mode_mgr.InPlayMode() && _world.GetTileOwner(fdata.voxel_pos.x, fdata.voxel_pos.y) != OWN_PARK) return;

	/* Normalize voxel position to the base ground voxel. */
	const Voxel *v = _world.GetVoxel(fdata.voxel_pos);
	assert(v->GetGroundType() != GTP_INVALID);
	uint8 slope = v->GetGroundSlope();
	if (IsImplodedSteepSlopeTop(slope)) {
		fdata.voxel_pos.z--; // Select base of the ground for the edge cursor.
		/* Post-pone 'slope' update until decided that a new fence position needs to be calculated. */
	}

	TileEdge edge = static_cast<TileEdge>(EDGE_NE + (fdata.cursor - CUR_TYPE_EDGE_NE));
	if (edge == this->fence_edge && fdata.voxel_pos == this->fence_base) return;

	/* New fence, or moved fence. Update the mouse selector. */
	this->fence_sel.MarkDirty();

	this->fence_edge = edge; // Store new edge and base position.
	this->fence_base = fdata.voxel_pos;

	/* Compute actual voxel that contains the fence. */
	if (IsImplodedSteepSlopeTop(slope)) {
		slope = _world.GetVoxel(fdata.voxel_pos)->GetGroundSlope();
	}
	fdata.voxel_pos.z += GetVoxelZOffsetForFence(edge, slope);

	this->fence_sel.SetPosition(fdata.voxel_pos.x, fdata.voxel_pos.y);
	this->fence_sel.AddVoxel(fdata.voxel_pos);
	this->fence_sel.SetupRideInfoSpace();
	this->fence_sel.SetFenceData(fdata.voxel_pos, this->fence_type, edge);

	this->fence_sel.MarkDirty();
}
Exemplo n.º 11
0
//--------------------------------------------------------------
void IntelFaceScanner::updateBitmap(PXCImage *newimage) 
{
	if(!newimage) return;

	PXCImage* image = newimage;
	PXCImage::ImageInfo info=image->QueryInfo();
    PXCImage::ImageData data;

	if(info.format == PXCImage::PIXEL_FORMAT_RGB32)
	{
		if (image->AcquireAccess(PXCImage::ACCESS_READ,PXCImage::PIXEL_FORMAT_RGB32, &data)>=PXC_STATUS_NO_ERROR) 
		{
			for(int i=0; i < info.height;i++) {
				memcpy_s((char*)(m_charBuffer+i*data.pitches[0]),info.width*4,data.planes[0]+i*data.pitches[0],info.width*4);
			}
			frame.setFromPixels(m_charBuffer, info.width, info.height, OF_IMAGE_COLOR_ALPHA, true);
			
			ScanningData fdata(frame);
			scanningData.send(fdata);

			image->ReleaseAccess(&data);
		}
	}
}
void
CartesianCellDoubleConservativeLinearRefine::refine(
   hier::Patch& fine,
   const hier::Patch& coarse,
   const int dst_component,
   const int src_component,
   const hier::Box& fine_box,
   const hier::IntVector& ratio) const
{
   const tbox::Dimension& dim(fine.getDim());
   TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, fine_box, ratio);

   std::shared_ptr<pdat::CellData<double> > cdata(
      SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
         coarse.getPatchData(src_component)));
   std::shared_ptr<pdat::CellData<double> > fdata(
      SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
         fine.getPatchData(dst_component)));
   TBOX_ASSERT(cdata);
   TBOX_ASSERT(fdata);
   TBOX_ASSERT(cdata->getDepth() == fdata->getDepth());

   const hier::Box cgbox(cdata->getGhostBox());

   const hier::Index& cilo = cgbox.lower();
   const hier::Index& cihi = cgbox.upper();
   const hier::Index& filo = fdata->getGhostBox().lower();
   const hier::Index& fihi = fdata->getGhostBox().upper();

   const std::shared_ptr<CartesianPatchGeometry> cgeom(
      SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         coarse.getPatchGeometry()));
   const std::shared_ptr<CartesianPatchGeometry> fgeom(
      SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         fine.getPatchGeometry()));

   TBOX_ASSERT(cgeom);
   TBOX_ASSERT(fgeom);

   const hier::Box coarse_box = hier::Box::coarsen(fine_box, ratio);
   const hier::Index& ifirstc = coarse_box.lower();
   const hier::Index& ilastc = coarse_box.upper();
   const hier::Index& ifirstf = fine_box.lower();
   const hier::Index& ilastf = fine_box.upper();

   const hier::IntVector tmp_ghosts(dim, 0);
   std::vector<double> diff0(cgbox.numberCells(0) + 1);
   pdat::CellData<double> slope0(cgbox, 1, tmp_ghosts);

   for (int d = 0; d < fdata->getDepth(); ++d) {
      if ((dim == tbox::Dimension(1))) {
         SAMRAI_F77_FUNC(cartclinrefcelldoub1d, CARTCLINREFCELLDOUB1D) (ifirstc(0),
            ilastc(0),
            ifirstf(0), ilastf(0),
            cilo(0), cihi(0),
            filo(0), fihi(0),
            &ratio[0],
            cgeom->getDx(),
            fgeom->getDx(),
            cdata->getPointer(d),
            fdata->getPointer(d),
            &diff0[0], slope0.getPointer());
      } else if ((dim == tbox::Dimension(2))) {

         std::vector<double> diff1(cgbox.numberCells(1) + 1);
         pdat::CellData<double> slope1(cgbox, 1, tmp_ghosts);

         SAMRAI_F77_FUNC(cartclinrefcelldoub2d, CARTCLINREFCELLDOUB2D) (ifirstc(0),
            ifirstc(1), ilastc(0), ilastc(1),
            ifirstf(0), ifirstf(1), ilastf(0), ilastf(1),
            cilo(0), cilo(1), cihi(0), cihi(1),
            filo(0), filo(1), fihi(0), fihi(1),
            &ratio[0],
            cgeom->getDx(),
            fgeom->getDx(),
            cdata->getPointer(d),
            fdata->getPointer(d),
            &diff0[0], slope0.getPointer(),
            &diff1[0], slope1.getPointer());
      } else if ((dim == tbox::Dimension(3))) {

         std::vector<double> diff1(cgbox.numberCells(1) + 1);
         pdat::CellData<double> slope1(cgbox, 1, tmp_ghosts);

         std::vector<double> diff2(cgbox.numberCells(2) + 1);
         pdat::CellData<double> slope2(cgbox, 1, tmp_ghosts);

         SAMRAI_F77_FUNC(cartclinrefcelldoub3d, CARTCLINREFCELLDOUB3D) (ifirstc(0),
            ifirstc(1), ifirstc(2),
            ilastc(0), ilastc(1), ilastc(2),
            ifirstf(0), ifirstf(1), ifirstf(2),
            ilastf(0), ilastf(1), ilastf(2),
            cilo(0), cilo(1), cilo(2),
            cihi(0), cihi(1), cihi(2),
            filo(0), filo(1), filo(2),
            fihi(0), fihi(1), fihi(2),
            &ratio[0],
            cgeom->getDx(),
            fgeom->getDx(),
            cdata->getPointer(d),
            fdata->getPointer(d),
            &diff0[0], slope0.getPointer(),
            &diff1[0], slope1.getPointer(),
            &diff2[0], slope2.getPointer());
      } else {
         TBOX_ERROR("CartesianCellDoubleConservativeLinearRefine error...\n"
            << "dim > 3 not supported." << std::endl);

      }
   }
}
void
CartesianFaceDoubleWeightedAverage::coarsen(
   hier::Patch& coarse,
   const hier::Patch& fine,
   const int dst_component,
   const int src_component,
   const hier::Box& coarse_box,
   const hier::IntVector& ratio) const
{
   const tbox::Dimension& dim(fine.getDim());

   TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, coarse_box, ratio);

   std::shared_ptr<pdat::FaceData<double> > fdata(
      SAMRAI_SHARED_PTR_CAST<pdat::FaceData<double>, hier::PatchData>(
         fine.getPatchData(src_component)));
   std::shared_ptr<pdat::FaceData<double> > cdata(
      SAMRAI_SHARED_PTR_CAST<pdat::FaceData<double>, hier::PatchData>(
         coarse.getPatchData(dst_component)));
   TBOX_ASSERT(fdata);
   TBOX_ASSERT(cdata);
   TBOX_ASSERT(cdata->getDepth() == fdata->getDepth());

   const hier::Index& filo = fdata->getGhostBox().lower();
   const hier::Index& fihi = fdata->getGhostBox().upper();
   const hier::Index& cilo = cdata->getGhostBox().lower();
   const hier::Index& cihi = cdata->getGhostBox().upper();

   const std::shared_ptr<CartesianPatchGeometry> fgeom(
      SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         fine.getPatchGeometry()));
   const std::shared_ptr<CartesianPatchGeometry> cgeom(
      SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         coarse.getPatchGeometry()));

   TBOX_ASSERT(fgeom);
   TBOX_ASSERT(cgeom);

   const hier::Index& ifirstc = coarse_box.lower();
   const hier::Index& ilastc = coarse_box.upper();

   for (int d = 0; d < cdata->getDepth(); ++d) {
      if ((dim == tbox::Dimension(1))) {
         SAMRAI_F77_FUNC(cartwgtavgfacedoub1d, CARTWGTAVGFACEDOUB1D) (ifirstc(0),
            ilastc(0),
            filo(0), fihi(0),
            cilo(0), cihi(0),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(0, d),
            cdata->getPointer(0, d));
      } else if ((dim == tbox::Dimension(2))) {
         SAMRAI_F77_FUNC(cartwgtavgfacedoub2d0, CARTWGTAVGFACEDOUB2D0) (ifirstc(0),
            ifirstc(1), ilastc(0), ilastc(1),
            filo(0), filo(1), fihi(0), fihi(1),
            cilo(0), cilo(1), cihi(0), cihi(1),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(0, d),
            cdata->getPointer(0, d));
         SAMRAI_F77_FUNC(cartwgtavgfacedoub2d1, CARTWGTAVGFACEDOUB2D1) (ifirstc(0),
            ifirstc(1), ilastc(0), ilastc(1),
            filo(0), filo(1), fihi(0), fihi(1),
            cilo(0), cilo(1), cihi(0), cihi(1),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(1, d),
            cdata->getPointer(1, d));
      } else if ((dim == tbox::Dimension(3))) {
         SAMRAI_F77_FUNC(cartwgtavgfacedoub3d0, CARTWGTAVGFACEDOUB3D0) (ifirstc(0),
            ifirstc(1), ifirstc(2),
            ilastc(0), ilastc(1), ilastc(2),
            filo(0), filo(1), filo(2),
            fihi(0), fihi(1), fihi(2),
            cilo(0), cilo(1), cilo(2),
            cihi(0), cihi(1), cihi(2),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(0, d),
            cdata->getPointer(0, d));
         SAMRAI_F77_FUNC(cartwgtavgfacedoub3d1, CARTWGTAVGFACEDOUB3D1) (ifirstc(0),
            ifirstc(1), ifirstc(2),
            ilastc(0), ilastc(1), ilastc(2),
            filo(0), filo(1), filo(2),
            fihi(0), fihi(1), fihi(2),
            cilo(0), cilo(1), cilo(2),
            cihi(0), cihi(1), cihi(2),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(1, d),
            cdata->getPointer(1, d));
         SAMRAI_F77_FUNC(cartwgtavgfacedoub3d2, CARTWGTAVGFACEDOUB3D2) (ifirstc(0),
            ifirstc(1), ifirstc(2),
            ilastc(0), ilastc(1), ilastc(2),
            filo(0), filo(1), filo(2),
            fihi(0), fihi(1), fihi(2),
            cilo(0), cilo(1), cilo(2),
            cihi(0), cihi(1), cihi(2),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(2, d),
            cdata->getPointer(2, d));
      } else if ((dim == tbox::Dimension(4))) {
         SAMRAI_F77_FUNC(cartwgtavgfacedoub4d0, CARTWGTAVGFACEDOUB4D0) (ifirstc(0),
            ifirstc(1), ifirstc(2), ifirstc(3),
            ilastc(0), ilastc(1), ilastc(2), ilastc(3),
            filo(0), filo(1), filo(2), filo(3),
            fihi(0), fihi(1), fihi(2), fihi(3),
            cilo(0), cilo(1), cilo(2), cilo(3),
            cihi(0), cihi(1), cihi(2), cihi(3),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(0, d),
            cdata->getPointer(0, d));
         SAMRAI_F77_FUNC(cartwgtavgfacedoub4d1, CARTWGTAVGFACEDOUB4D1) (ifirstc(0),
            ifirstc(1), ifirstc(2), ifirstc(3),
            ilastc(0), ilastc(1), ilastc(2), ilastc(3),
            filo(0), filo(1), filo(2), filo(3),
            fihi(0), fihi(1), fihi(2), fihi(3),
            cilo(0), cilo(1), cilo(2), cilo(3),
            cihi(0), cihi(1), cihi(2), cihi(3),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(1, d),
            cdata->getPointer(1, d));
         SAMRAI_F77_FUNC(cartwgtavgfacedoub4d2, CARTWGTAVGFACEDOUB4D2) (ifirstc(0),
            ifirstc(1), ifirstc(2), ifirstc(3),
            ilastc(0), ilastc(1), ilastc(2), ilastc(3),
            filo(0), filo(1), filo(2), filo(3),
            fihi(0), fihi(1), fihi(2), fihi(3),
            cilo(0), cilo(1), cilo(2), cilo(3),
            cihi(0), cihi(1), cihi(2), cihi(3),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(2, d),
            cdata->getPointer(2, d));
         SAMRAI_F77_FUNC(cartwgtavgfacedoub4d3, CARTWGTAVGFACEDOUB4D3) (ifirstc(0),
            ifirstc(1), ifirstc(2), ifirstc(3),
            ilastc(0), ilastc(1), ilastc(2), ilastc(3),
            filo(0), filo(1), filo(2), filo(3),
            fihi(0), fihi(1), fihi(2), fihi(3),
            cilo(0), cilo(1), cilo(2), cilo(3),
            cihi(0), cihi(1), cihi(2), cihi(3),
            &ratio[0],
            fgeom->getDx(),
            cgeom->getDx(),
            fdata->getPointer(3, d),
            cdata->getPointer(3, d));
      } else {
         TBOX_ERROR("CartesianFaceDoubleWeightedAverage error...\n"
            << "dim > 4 not supported." << std::endl);
      }
   }
}
Exemplo n.º 14
0
bool test_one_file(std::ifstream& in, int verbose_level)
{
  std::list<X_monotone_curve_2> xcurves;
  std::list<Point_2> isolated_points;
  read_arr(in, std::back_inserter(xcurves),
           std::back_inserter(isolated_points));
  Arrangement arr1;
  construct_arr(arr1, xcurves.begin(), xcurves.end(),
                isolated_points.begin(), isolated_points.end(), verbose_level);
  isolated_points.clear();
  xcurves.clear();
  init_arr(arr1, verbose_level);

  read_arr(in, std::back_inserter(xcurves),
           std::back_inserter(isolated_points));
  Arrangement arr2;
  construct_arr(arr2, xcurves.begin(), xcurves.end(),
                isolated_points.begin(), isolated_points.end(), verbose_level);
  isolated_points.clear();
  xcurves.clear();
  init_arr(arr2, verbose_level);

  // Read the number of cells left.
  Arrangement::Size num_vertices, num_edges, num_faces;
  in >> num_vertices >> num_edges >> num_faces;

  // Read the expected face data:
  std::vector<int> fdata(num_faces);
  std::copy(std::istream_iterator<int>(in), std::istream_iterator<int>(),
            fdata.begin());

  Arrangement arr;
  Overlay_traits overlay_traits;
  if (verbose_level > 2) std::cout << "overlaying" << " ... "; std::cout.flush();
  CGAL::overlay(arr1, arr2, arr, overlay_traits);
  if (verbose_level > 2) std::cout << "overlaid" << std::endl;

  // Verify the resulting arrangement.
  Arrangement::Size num_vertices_res = arr.number_of_vertices();
  Arrangement::Size num_edges_res = arr.number_of_edges();
  Arrangement::Size num_faces_res = arr.number_of_faces();

  if (verbose_level > 0) std::cout << "Arrangement Output: " << std::endl;

  if (verbose_level > 1) {
    std::cout << "Halfedge Data: " << std::endl;
    Halfedge_iterator heit;
    for (heit = arr.halfedges_begin(); heit != arr.halfedges_end(); ++heit)
      std::cout << heit->source()->point() << " "
                << heit->target()->point() << " " << heit->data()
                << std::endl;
  }

  if (verbose_level > 0) {
    std::cout << "Face Data: " << std::endl;
    Face_iterator fit;
    for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit)
      std::cout << fit->data() << std::endl;
  }

  if ((num_vertices_res != num_vertices) ||
      (num_edges_res != num_edges) ||
      (num_faces_res != num_faces))
  {
    std::cerr << "ERROR: The number of arrangement cells is incorrect:"
              << std::endl
              << "   V = " << arr.number_of_vertices()
              << ", E = " << arr.number_of_edges()
              << ", F = " << arr.number_of_faces()
              << std::endl;
    arr.clear();
    return false;
  }

  std::vector<int> fdata_res(num_faces);
  std::vector<int>::iterator it = fdata_res.begin();
  Face_iterator fit;
  for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit)
     *it++ = fit->data();
  std::sort(fdata_res.begin(), fdata_res.end());
  if (! std::equal(fdata_res.begin(), fdata_res.end(), fdata.begin())) {
    std::cerr << "ERROR: Incorrect face data:" << std::endl;
    std::copy(fdata_res.begin(), fdata_res.end(),
              std::ostream_iterator<int>(std::cout, "\n"));
    arr.clear();
    return false;
  }

  arr.clear();
  return true;
}
void
CartesianNodeComplexLinearRefine::refine(
   hier::Patch& fine,
   const hier::Patch& coarse,
   const int dst_component,
   const int src_component,
   const hier::Box& fine_box,
   const hier::IntVector& ratio) const
{
   const tbox::Dimension& dim(fine.getDim());
   TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, fine_box, ratio);

   boost::shared_ptr<pdat::NodeData<dcomplex> > cdata(
      BOOST_CAST<pdat::NodeData<dcomplex>, hier::PatchData>(
         coarse.getPatchData(src_component)));
   boost::shared_ptr<pdat::NodeData<dcomplex> > fdata(
      BOOST_CAST<pdat::NodeData<dcomplex>, hier::PatchData>(
         fine.getPatchData(dst_component)));
   TBOX_ASSERT(cdata);
   TBOX_ASSERT(fdata);
   TBOX_ASSERT(cdata->getDepth() == fdata->getDepth());

   const hier::Box cgbox(cdata->getGhostBox());

   const hier::Index cilo = cgbox.lower();
   const hier::Index cihi = cgbox.upper();
   const hier::Index filo = fdata->getGhostBox().lower();
   const hier::Index fihi = fdata->getGhostBox().upper();

   const boost::shared_ptr<CartesianPatchGeometry> cgeom(
      BOOST_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         coarse.getPatchGeometry()));
   const boost::shared_ptr<CartesianPatchGeometry> fgeom(
      BOOST_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         fine.getPatchGeometry()));

   TBOX_ASSERT(cgeom);
   TBOX_ASSERT(fgeom);

   const hier::Box coarse_box = hier::Box::coarsen(fine_box, ratio);
   const hier::Index ifirstc = coarse_box.lower();
   const hier::Index ilastc = coarse_box.upper();
   const hier::Index ifirstf = fine_box.lower();
   const hier::Index ilastf = fine_box.upper();

   for (int d = 0; d < fdata->getDepth(); ++d) {
      if ((dim == tbox::Dimension(1))) {
         SAMRAI_F77_FUNC(cartlinrefnodecplx1d, CARTLINREFNODECPLX1D) (ifirstc(0),
            ilastc(0),
            ifirstf(0), ilastf(0),
            cilo(0), cihi(0),
            filo(0), fihi(0),
            &ratio[0],
            cgeom->getDx(),
            fgeom->getDx(),
            cdata->getPointer(d),
            fdata->getPointer(d));
      } else if ((dim == tbox::Dimension(2))) {
         SAMRAI_F77_FUNC(cartlinrefnodecplx2d, CARTLINREFNODECPLX2D) (ifirstc(0),
            ifirstc(1), ilastc(0), ilastc(1),
            ifirstf(0), ifirstf(1), ilastf(0), ilastf(1),
            cilo(0), cilo(1), cihi(0), cihi(1),
            filo(0), filo(1), fihi(0), fihi(1),
            &ratio[0],
            cgeom->getDx(),
            fgeom->getDx(),
            cdata->getPointer(d),
            fdata->getPointer(d));
      } else if ((dim == tbox::Dimension(3))) {
         SAMRAI_F77_FUNC(cartlinrefnodecplx3d, CARTLINREFNODECPLX3D) (ifirstc(0),
            ifirstc(1), ifirstc(2),
            ilastc(0), ilastc(1), ilastc(2),
            ifirstf(0), ifirstf(1), ifirstf(2),
            ilastf(0), ilastf(1), ilastf(2),
            cilo(0), cilo(1), cilo(2),
            cihi(0), cihi(1), cihi(2),
            filo(0), filo(1), filo(2),
            fihi(0), fihi(1), fihi(2),
            &ratio[0],
            cgeom->getDx(),
            fgeom->getDx(),
            cdata->getPointer(d),
            fdata->getPointer(d));
      } else {
         TBOX_ERROR("CartesianNodeComplexLinearRefine error...\n"
            << "dim > 3 not supported." << std::endl);
      }
   }
}
Exemplo n.º 16
0
void
EdgeFloatConstantRefine::refine(
   hier::Patch& fine,
   const hier::Patch& coarse,
   const int dst_component,
   const int src_component,
   const hier::BoxOverlap& fine_overlap,
   const hier::IntVector& ratio) const
{
   const tbox::Dimension& dim(fine.getDim());

   std::shared_ptr<EdgeData<float> > cdata(
      SAMRAI_SHARED_PTR_CAST<EdgeData<float>, hier::PatchData>(
         coarse.getPatchData(src_component)));
   std::shared_ptr<EdgeData<float> > fdata(
      SAMRAI_SHARED_PTR_CAST<EdgeData<float>, hier::PatchData>(
         fine.getPatchData(dst_component)));

   const EdgeOverlap* t_overlap = CPP_CAST<const EdgeOverlap *>(&fine_overlap);

   TBOX_ASSERT(t_overlap != 0);

   TBOX_ASSERT(cdata);
   TBOX_ASSERT(fdata);
   TBOX_ASSERT(cdata->getDepth() == fdata->getDepth());
   TBOX_ASSERT_OBJDIM_EQUALITY3(fine, coarse, ratio);

   const hier::Box& cgbox(cdata->getGhostBox());

   const hier::Index& cilo = cgbox.lower();
   const hier::Index& cihi = cgbox.upper();
   const hier::Index& filo = fdata->getGhostBox().lower();
   const hier::Index& fihi = fdata->getGhostBox().upper();

   for (int axis = 0; axis < dim.getValue(); ++axis) {
      const hier::BoxContainer& boxes = t_overlap->getDestinationBoxContainer(axis);

      for (hier::BoxContainer::const_iterator b = boxes.begin();
           b != boxes.end(); ++b) {

         hier::Box fine_box(*b);
         TBOX_ASSERT_DIM_OBJDIM_EQUALITY1(dim, fine_box);

         for (tbox::Dimension::dir_t i = 0; i < dim.getValue(); ++i) {
            if (i != axis) {
               fine_box.setUpper(i, fine_box.upper(i) - 1);
            }
         }

         const hier::Box coarse_box = hier::Box::coarsen(fine_box, ratio);
         const hier::Index& ifirstc = coarse_box.lower();
         const hier::Index& ilastc = coarse_box.upper();
         const hier::Index& ifirstf = fine_box.lower();
         const hier::Index& ilastf = fine_box.upper();

         for (int d = 0; d < fdata->getDepth(); ++d) {
            if (dim == tbox::Dimension(1)) {
               SAMRAI_F77_FUNC(conrefedgeflot1d, CONREFEDGEFLOT1D) (
                  ifirstc(0), ilastc(0),
                  ifirstf(0), ilastf(0),
                  cilo(0), cihi(0),
                  filo(0), fihi(0),
                  &ratio[0],
                  cdata->getPointer(0, d),
                  fdata->getPointer(0, d));
            } else if (dim == tbox::Dimension(2)) {
               if (axis == 0) {
                  SAMRAI_F77_FUNC(conrefedgeflot2d0, CONREFEDGEFLOT2D0) (
                     ifirstc(0), ifirstc(1), ilastc(0), ilastc(1),
                     ifirstf(0), ifirstf(1), ilastf(0), ilastf(1),
                     cilo(0), cilo(1), cihi(0), cihi(1),
                     filo(0), filo(1), fihi(0), fihi(1),
                     &ratio[0],
                     cdata->getPointer(0, d),
                     fdata->getPointer(0, d));
               } else if (axis == 1) {
                  SAMRAI_F77_FUNC(conrefedgeflot2d1, CONREFEDGEFLOT2D1) (
                     ifirstc(0), ifirstc(1), ilastc(0), ilastc(1),
                     ifirstf(0), ifirstf(1), ilastf(0), ilastf(1),
                     cilo(0), cilo(1), cihi(0), cihi(1),
                     filo(0), filo(1), fihi(0), fihi(1),
                     &ratio[0],
                     cdata->getPointer(1, d),
                     fdata->getPointer(1, d));
               }
            } else if (dim == tbox::Dimension(3)) {
               if (axis == 0) {
                  SAMRAI_F77_FUNC(conrefedgeflot3d0, CONREFEDGEFLOT3D0) (
                     ifirstc(0), ifirstc(1), ifirstc(2),
                     ilastc(0), ilastc(1), ilastc(2),
                     ifirstf(0), ifirstf(1), ifirstf(2),
                     ilastf(0), ilastf(1), ilastf(2),
                     cilo(0), cilo(1), cilo(2),
                     cihi(0), cihi(1), cihi(2),
                     filo(0), filo(1), filo(2),
                     fihi(0), fihi(1), fihi(2),
                     &ratio[0],
                     cdata->getPointer(0, d),
                     fdata->getPointer(0, d));
               } else if (axis == 1) {
                  SAMRAI_F77_FUNC(conrefedgeflot3d1, CONREFEDGEFLOT3D1) (
                     ifirstc(0), ifirstc(1), ifirstc(2),
                     ilastc(0), ilastc(1), ilastc(2),
                     ifirstf(0), ifirstf(1), ifirstf(2),
                     ilastf(0), ilastf(1), ilastf(2),
                     cilo(0), cilo(1), cilo(2),
                     cihi(0), cihi(1), cihi(2),
                     filo(0), filo(1), filo(2),
                     fihi(0), fihi(1), fihi(2),
                     &ratio[0],
                     cdata->getPointer(1, d),
                     fdata->getPointer(1, d));
               } else if (axis == 2) {
                  SAMRAI_F77_FUNC(conrefedgeflot3d2, CONREFEDGEFLOT3D2) (
                     ifirstc(0), ifirstc(1), ifirstc(2),
                     ilastc(0), ilastc(1), ilastc(2),
                     ifirstf(0), ifirstf(1), ifirstf(2),
                     ilastf(0), ilastf(1), ilastf(2),
                     cilo(0), cilo(1), cilo(2),
                     cihi(0), cihi(1), cihi(2),
                     filo(0), filo(1), filo(2),
                     fihi(0), fihi(1), fihi(2),
                     &ratio[0],
                     cdata->getPointer(2, d),
                     fdata->getPointer(2, d));
               }
            } else {
               TBOX_ERROR(
                  "EdgeFloatConstantRefine::refine dimension > 3 not supported"
                  << std::endl);
            }
         }
      }
   }
}
Exemplo n.º 17
0
bool loadObj( std::vector<Geometry> &geomList, const std::string &filename, float scale, int flags)
{
    std::ifstream file;
    file.open(filename.c_str(), std::ios::in);

    std::cout<<"loading "<<filename<<std::endl;

    if(file.fail())
    {
        std::cout<<"loadObj failed, could not read "<<std::endl;
        return 1;
    }

    VertexBank vb;

    Geometry g;
    std::string line,param;

    std::vector<vec3> tempVertex;
    std::vector<vec3> tempNormal;
    std::vector<vec2> tempTexCoord;

    tempVertex.reserve(10000);
    tempNormal.reserve(10000);
    tempTexCoord.reserve(10000);
    
    std::vector<std::vector<int> > vertexUsed;
    std::vector<int> texCoordUsed;
    int tempSG = 0;

    std::vector<size_t> vertexRemap;
    std::vector<size_t> normalRemap;
    std::vector<size_t> texCoordRemap;

    std::vector<int> resetVector;
    resetVector.resize(1,-1);

    std::string tempName;

    while( !file.eof() && file.good() )
    {
        std::getline(file,line);

        #ifdef DEBUG
        std::cout<<line<<"\n";
        #endif
        Tokenizer token(line);

        param = token.getToken();
        if(param == "v")
        {
            vec3 vertex;

            vertex.x = scale*toFloat(token.getToken());
            vertex.y = scale*toFloat(token.getToken());
            vertex.z = scale*toFloat(token.getToken());

            //tempVertex.push_back(vertex);
            //vertexUsed.push_back(resetVector);
            vertexRemap.push_back( insertUnique(tempVertex, vertex) );
        }
        else if(param == "f")
        {
            ivec4 vdata(-1), tdata(-1), ndata(-1), fdata(-1);

            for(int i=0; i<(int)token.size()-1; ++i)
            {
                param = token.getToken();
                getIndices(param, vdata[i], tdata[i], ndata[i],
                    hasVertex,
                    hasTexCoord && !(flags & LOADOBJ_IGNORE_TEXCOORDS),
                    hasNormal && !(flags & LOADOBJ_IGNORE_NORMALS) );

                int remappedV = (vdata[i] > -1) ? vdata[i] : -1;
                int remappedN = (ndata[i] > -1) ? ndata[i] : -1;
                int remappedT = (tdata[i] > -1) ? tdata[i] : -1;

                int index;
                //printf("Checking vertex uniqueness \n");
                if(vb.isUnique(remappedV, remappedN, remappedT, index))
                {
                    index = g.getVertexSize();

                    Geometry::sVertex tv;

                    assert( remappedV < (int)tempVertex.size() );
                    tv.position = tempVertex[ remappedV ];

                    if(remappedT > -1)
                    {
                        assert( remappedT < (int)tempTexCoord.size() );
                        tv.texCoord = tempTexCoord[ remappedT ];
                    }
                    if(remappedN > -1)
                    {
                        assert( remappedN < (int)tempNormal.size() );
                        tv.normal = tempNormal[ remappedN ];
                    }

                    g.addVertex(tv);
                }

                assert(index < (int)g.getVertexSize());
                fdata[i] = index;

                // if(tempSG > (int)vertexUsed[vdata[i]].size()-1)
                //     vertexUsed[vdata[i]].resize(tempSG+1,-1);

                // if(vertexUsed[vdata[i]][tempSG] > -1)
                //     fdata[i] = vertexUsed[vdata[i]][tempSG];
                // else
                // {
                //     vertexUsed[vdata[i]][tempSG] = (int)g.vertices.size();

                //     fdata[i] = g.getVertexSize();

                //     Geometry::sVertex tv;
                //     tv.position = tempVertex[vdata[i]];
                //     //tv.nx = tv.ny = tv.nz = tv.s = tv.t = 0.0f;

                //     if(vtdata[i]>-1 && !(flags & LOADOBJ_IGNORE_TEXCOORDS))
                //     {
                //         assert( vtdata[i] < tempTexCoord.size() );
                //         tv.texCoord = tempTexCoord[vtdata[i]];
                //     }
                //     if(ndata[i]>-1 && !(flags & LOADOBJ_IGNORE_NORMALS))
                //     {
                //         assert( ndata[i] < tempNormal.size() );
                //         tv.normal = tempNormal[ndata[i]];
                //     }

                //     g.addVertex(tv);
                // }
            }
            // if its a triangle, just insert.
            // However if its a quad, then insert the two triangles forming the quad.
            uvec3 t;
            t[0] = fdata[0];
            t[1] = fdata[1];
            t[2] = fdata[2];

            g.addTriangle(t);

            if(fdata[3] != -1)
            {
                t[0] = fdata[3];
                t[1] = fdata[0];
                t[2] = fdata[2];

                g.addTriangle(t);
            }
        }
        else if(param == "vt")
        {
            vec2 tc;

            tc.x = toFloat(token.getToken());
            tc.y = toFloat(token.getToken());

            //tempTexCoord.push_back(tc);
            texCoordRemap.push_back( insertUnique(tempTexCoord, tc) );
        }
        else if(param == "vn")
        {
            vec3 normal;

            normal.x = toFloat(token.getToken());
            normal.y = toFloat(token.getToken());
            normal.z = toFloat(token.getToken());

            //tempNormal.push_back(normal);
            normalRemap.push_back( insertUnique(tempNormal, normal) );
        }
        else if(param == "s")
            tempSG = toInt(token.getToken());
        else if(param == "g")
        {
            /*if(first)
                first=false;
            else
            {
                g.process();
                geomList.push_back(g);
            }

            for(unsigned int i=0; i<vertexUsed.size(); ++i)
                vertexUsed[i].clear();
            
            g.clear();
            */
        }

        if(file.eof())
            break;
    }
    file.close();
    printf("tempVertex.size() = %i \n", (int)tempVertex.size());
    printf("tempNormal.size() = %i \n", (int)tempNormal.size());
    printf("tempTexCoord.size() = %i \n", (int)tempTexCoord.size());
    printf("Reading is done, gonna process \n");
    g.process();
    geomList.push_back(g);

    std::cout<<"done reading "<<filename<<std::endl;

    return 0;
}
Exemplo n.º 18
0
void
CartesianSideFloatWeightedAverage::coarsen(
   hier::Patch& coarse,
   const hier::Patch& fine,
   const int dst_component,
   const int src_component,
   const hier::Box& coarse_box,
   const hier::IntVector& ratio) const
{
   const tbox::Dimension& dim(fine.getDim());

   TBOX_ASSERT_DIM_OBJDIM_EQUALITY3(dim, coarse, coarse_box, ratio);

   std::shared_ptr<pdat::SideData<float> > fdata(
      SAMRAI_SHARED_PTR_CAST<pdat::SideData<float>, hier::PatchData>(
         fine.getPatchData(src_component)));
   std::shared_ptr<pdat::SideData<float> > cdata(
      SAMRAI_SHARED_PTR_CAST<pdat::SideData<float>, hier::PatchData>(
         coarse.getPatchData(dst_component)));
   TBOX_ASSERT(fdata);
   TBOX_ASSERT(cdata);
   TBOX_ASSERT(cdata->getDepth() == fdata->getDepth());
   const hier::IntVector& directions = cdata->getDirectionVector();
   TBOX_ASSERT(directions ==
      hier::IntVector::min(directions, fdata->getDirectionVector()));

   const hier::Index& filo = fdata->getGhostBox().lower();
   const hier::Index& fihi = fdata->getGhostBox().upper();
   const hier::Index& cilo = cdata->getGhostBox().lower();
   const hier::Index& cihi = cdata->getGhostBox().upper();

   const std::shared_ptr<CartesianPatchGeometry> fgeom(
      SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         fine.getPatchGeometry()));
   const std::shared_ptr<CartesianPatchGeometry> cgeom(
      SAMRAI_SHARED_PTR_CAST<CartesianPatchGeometry, hier::PatchGeometry>(
         coarse.getPatchGeometry()));

   TBOX_ASSERT(fgeom);
   TBOX_ASSERT(cgeom);

   const hier::Index& ifirstc = coarse_box.lower();
   const hier::Index& ilastc = coarse_box.upper();

   for (int d = 0; d < cdata->getDepth(); ++d) {
      if ((dim == tbox::Dimension(1))) {
         if (directions(0)) {
            SAMRAI_F77_FUNC(cartwgtavgsideflot1d, CARTWGTAVGSIDEFLOT1D) (ifirstc(0),
               ilastc(0),
               filo(0), fihi(0),
               cilo(0), cihi(0),
               &ratio[0],
               fgeom->getDx(),
               cgeom->getDx(),
               fdata->getPointer(0, d),
               cdata->getPointer(0, d));
         }
      } else if ((dim == tbox::Dimension(2))) {
         if (directions(0)) {
            SAMRAI_F77_FUNC(cartwgtavgsideflot2d0, CARTWGTAVGSIDEFLOT2D0) (ifirstc(0),
               ifirstc(1), ilastc(0), ilastc(1),
               filo(0), filo(1), fihi(0), fihi(1),
               cilo(0), cilo(1), cihi(0), cihi(1),
               &ratio[0],
               fgeom->getDx(),
               cgeom->getDx(),
               fdata->getPointer(0, d),
               cdata->getPointer(0, d));
         }
         if (directions(1)) {
            SAMRAI_F77_FUNC(cartwgtavgsideflot2d1, CARTWGTAVGSIDEFLOT2D1) (ifirstc(0),
               ifirstc(1), ilastc(0), ilastc(1),
               filo(0), filo(1), fihi(0), fihi(1),
               cilo(0), cilo(1), cihi(0), cihi(1),
               &ratio[0],
               fgeom->getDx(),
               cgeom->getDx(),
               fdata->getPointer(1, d),
               cdata->getPointer(1, d));
         }
      } else if ((dim == tbox::Dimension(3))) {
         if (directions(0)) {
            SAMRAI_F77_FUNC(cartwgtavgsideflot3d0, CARTWGTAVGSIDEFLOT3D0) (ifirstc(0),
               ifirstc(1), ifirstc(2),
               ilastc(0), ilastc(1), ilastc(2),
               filo(0), filo(1), filo(2),
               fihi(0), fihi(1), fihi(2),
               cilo(0), cilo(1), cilo(2),
               cihi(0), cihi(1), cihi(2),
               &ratio[0],
               fgeom->getDx(),
               cgeom->getDx(),
               fdata->getPointer(0, d),
               cdata->getPointer(0, d));
         }
         if (directions(1)) {
            SAMRAI_F77_FUNC(cartwgtavgsideflot3d1, CARTWGTAVGSIDEFLOT3D1) (ifirstc(0),
               ifirstc(1), ifirstc(2),
               ilastc(0), ilastc(1), ilastc(2),
               filo(0), filo(1), filo(2),
               fihi(0), fihi(1), fihi(2),
               cilo(0), cilo(1), cilo(2),
               cihi(0), cihi(1), cihi(2),
               &ratio[0],
               fgeom->getDx(),
               cgeom->getDx(),
               fdata->getPointer(1, d),
               cdata->getPointer(1, d));
         }
         if (directions(2)) {
            SAMRAI_F77_FUNC(cartwgtavgsideflot3d2, CARTWGTAVGSIDEFLOT3D2) (ifirstc(0),
               ifirstc(1), ifirstc(2),
               ilastc(0), ilastc(1), ilastc(2),
               filo(0), filo(1), filo(2),
               fihi(0), fihi(1), fihi(2),
               cilo(0), cilo(1), cilo(2),
               cihi(0), cihi(1), cihi(2),
               &ratio[0],
               fgeom->getDx(),
               cgeom->getDx(),
               fdata->getPointer(2, d),
               cdata->getPointer(2, d));
         }
      } else {
         TBOX_ERROR("CartesianSideFloatWeightedAverage error...\n"
            << "dim > 3 not supported." << std::endl);
      }
   }
}
Exemplo n.º 19
0
void
OuternodeDoubleInjection::coarsen(
   hier::Patch& coarse,
   const hier::Patch& fine,
   const int dst_component,
   const int src_component,
   const hier::Box& coarse_box,
   const hier::IntVector& ratio) const
{
   const tbox::Dimension& dim(fine.getDim());

   boost::shared_ptr<OuternodeData<double> > fdata(
      BOOST_CAST<OuternodeData<double>, hier::PatchData>(
         fine.getPatchData(src_component)));
   boost::shared_ptr<OuternodeData<double> > cdata(
      BOOST_CAST<OuternodeData<double>, hier::PatchData>(
         coarse.getPatchData(dst_component)));

   TBOX_ASSERT(fdata);
   TBOX_ASSERT(cdata);
   TBOX_ASSERT(cdata->getDepth() == fdata->getDepth());
   TBOX_ASSERT_OBJDIM_EQUALITY4(coarse, fine, coarse_box, ratio);

   const hier::Index filo = fine.getBox().lower();
   const hier::Index fihi = fine.getBox().upper();
   const hier::Index cilo = coarse.getBox().lower();
   const hier::Index cihi = coarse.getBox().upper();

   const hier::Index ifirstc = coarse_box.lower();
   const hier::Index ilastc = coarse_box.upper();

   for (int i = 0; i < 2; ++i) {

      for (int axis = 0; axis < dim.getValue(); ++axis) {

         if (cdata->dataExists(axis)) {

            for (int d = 0; d < cdata->getDepth(); ++d) {

               if (dim == tbox::Dimension(1)) {
                  SAMRAI_F77_FUNC(conavgouternodedoub1d,
                     CONAVGOUTERNODEDOUB1D) (ifirstc(0), ilastc(0),
                     filo(0), fihi(0),
                     cilo(0), cihi(0),
                     &ratio[0],
                     fdata->getPointer(axis, i, d),
                     cdata->getPointer(axis, i, d));
               } else if (dim == tbox::Dimension(2)) {
                  if (axis == 0) {
                     SAMRAI_F77_FUNC(conavgouternodedoub2d0,
                        CONAVGOUTERNODEDOUB2D0) (ifirstc(0), ifirstc(1),
                        ilastc(0), ilastc(1),
                        filo(0), filo(1),
                        fihi(0), fihi(1),
                        cilo(0), cilo(1),
                        cihi(0), cihi(1),
                        &ratio[0],
                        fdata->getPointer(axis, i, d),
                        cdata->getPointer(axis, i, d));
                  }

                  if (axis == 1) {
                     SAMRAI_F77_FUNC(conavgouternodedoub2d1,
                        CONAVGOUTERNODEDOUB2D1) (ifirstc(0), ifirstc(1),
                        ilastc(0), ilastc(1),
                        filo(0), filo(1),
                        fihi(0), fihi(1),
                        cilo(0), cilo(1),
                        cihi(0), cihi(1),
                        &ratio[0],
                        fdata->getPointer(axis, i, d),
                        cdata->getPointer(axis, i, d));
                  }
               } else if (dim == tbox::Dimension(3)) {
                  if (axis == 0) {
                     SAMRAI_F77_FUNC(conavgouternodedoub3d0,
                        CONAVGOUTERNODEDOUB3D0) (ifirstc(0), ifirstc(1),
                        ifirstc(2),
                        ilastc(0), ilastc(1), ilastc(2),
                        filo(0), filo(1), filo(2),
                        fihi(0), fihi(1), fihi(2),
                        cilo(0), cilo(1), cilo(2),
                        cihi(0), cihi(1), cihi(2),
                        &ratio[0],
                        fdata->getPointer(axis, i, d),
                        cdata->getPointer(axis, i, d));
                  }
                  if (axis == 1) {
                     SAMRAI_F77_FUNC(conavgouternodedoub3d1,
                        CONAVGOUTERNODEDOUB3D1) (ifirstc(0), ifirstc(1),
                        ifirstc(2),
                        ilastc(0), ilastc(1), ilastc(2),
                        filo(0), filo(1), filo(2),
                        fihi(0), fihi(1), fihi(2),
                        cilo(0), cilo(1), cilo(2),
                        cihi(0), cihi(1), cihi(2),
                        &ratio[0],
                        fdata->getPointer(axis, i, d),
                        cdata->getPointer(axis, i, d));
                  }
                  if (axis == 2) {
                     SAMRAI_F77_FUNC(conavgouternodedoub3d2,
                        CONAVGOUTERNODEDOUB3D2) (ifirstc(0), ifirstc(1),
                        ifirstc(2),
                        ilastc(0), ilastc(1), ilastc(2),
                        filo(0), filo(1), filo(2),
                        fihi(0), fihi(1), fihi(2),
                        cilo(0), cilo(1), cilo(2),
                        cihi(0), cihi(1), cihi(2),
                        &ratio[0],
                        fdata->getPointer(axis, i, d),
                        cdata->getPointer(axis, i, d));
                  }
               }

            }
         }
      }
   }
}