bool BracketIsValid(avtPoincareIC *poincare_ic)
{
  Vector xzplane(0,1,0);
  FieldlineLib fieldlib;
  avtPoincareIC *_a = poincare_ic->a_IC;
  avtPoincareIC *_b = poincare_ic;
  avtPoincareIC *_c = poincare_ic->c_IC;        
  std::vector<avtVector> a_puncturePoints;
  std::vector<avtVector> b_puncturePoints;
  std::vector<avtVector> c_puncturePoints;
  fieldlib.getPunctures(_a->points,xzplane,a_puncturePoints);
  fieldlib.getPunctures(_b->points,xzplane,b_puncturePoints);
  fieldlib.getPunctures(_c->points,xzplane,c_puncturePoints);
                
  // Need to get distances for each a, b & c
  int a_i = FindMinimizationIndex(_a);
  int b_i = FindMinimizationIndex(_b);
  int c_i = FindMinimizationIndex(_c);

  if (3 <= RATIONAL_DEBUG)
    {
      std::cerr << "LINE " << __LINE__ << "  " << "a_i, b_i, c_i: "             <<a_i;
      if (a_i > -1)
        std::cerr <<"\n"<< VectorToString(a_puncturePoints[a_i])<<",\n"<<b_i;
      if (b_i > -1) 
        std::cerr << VectorToString(b_puncturePoints[b_i])<<",\n"<<c_i;
      if (c_i > -1)     
        std::cerr << VectorToString(c_puncturePoints[c_i]);
      std::cerr << std::endl;
    }
      
  return !(a_i == -1 || b_i == -1 || c_i == -1);
}
//*******************
// To start the minimization, we need to define three points
// If the middle point ('b) is already lower than the
// other two we can go straight to
// minimization. Otherwise, we have to bracket the
// minimum.  First things first, setup the two new
// points (b & c) and send them off
bool PrepareToBracket(avtPoincareIC *seed,
                      avtVector &newA,
                      avtVector &newB,
                      avtVector &newC)
{
  if (5 <= RATIONAL_DEBUG)
    std::cerr<< "Line: " << __LINE__ <<" Preparing to bracket the minimum"<<std::endl;
  
  Vector xzplane(0,1,0);
  FieldlineLib fieldlib;
  
  std::vector<avtVector> seed_puncture_points;
  fieldlib.getPunctures( seed->points, xzplane,
                         seed_puncture_points);
  avtVector maxPuncture;
  avtVector origPt1 = seed->properties.rationalPt1;
  avtVector origPt2 = seed->properties.rationalPt2;
  int ix = FindMinimizationIndex(seed);
  if (1 <= RATIONAL_DEBUG)
    cerr <<"Line: "<<__LINE__<< " Bracketing inside Original Rational Pts:\n"<<VectorToString(origPt1)<<"\n"<<VectorToString(origPt2)<<std::endl;
  if (ix < 0)
    return false;  

  maxPuncture = seed_puncture_points[ix];
  
  avtVector origChord = origPt2 - origPt1;
  avtVector perpendicular = -origChord.cross(avtVector(0,1,0));

  double xa = (origPt1 - maxPuncture).dot(perpendicular);
  perpendicular.normalize();
  
  double minDist = 2 * MAX_SPACING;
  if (xa < minDist)
    xa = minDist;

  avtVector intersection = maxPuncture + xa * perpendicular;

  cerr << "Max Puncture: "<<VectorToString(maxPuncture)<<"\nxa: "<<xa<<"\nintersection: "<<VectorToString(intersection)<<"\n";
  
  avtVector newPt1 = intersection;
  avtVector newPt2 = maxPuncture + GOLD * (newPt1 - maxPuncture);

  newPt1[1] =  Z_OFFSET;
  newPt2[1] =  Z_OFFSET;
  
  newA = maxPuncture;
  newB = newPt1;
  newC = newPt2;

  if (1 <= RATIONAL_DEBUG)
    cerr<<"LINE "<<__LINE__<<"New A,B,C:\n"<< VectorToString(newA) <<"\n"<< VectorToString(newB) <<"\n"<< VectorToString(newC) <<"\n";

  seed->properties.analysisMethod = FieldlineProperties::RATIONAL_SEARCH;
  seed->properties.searchState = FieldlineProperties::MINIMIZING_A;
  
  return true;
}
예제 #3
0
	void ParticleCloud::WriteHairFile(XSI::Geometry& oGeom, CString hairFilePath)
	{
		ofstream f(hairFilePath.GetAsciiString(), ios::out | ios::binary);

		CICEAttributeDataArrayVector3f dataArrayPosition;
		oGeom.GetICEAttributeFromName(L"PointPosition").GetDataArray(dataArrayPosition);

		CICEAttributeDataArrayLong dataArrayStrandCount;
		oGeom.GetICEAttributeFromName(L"StrandCount").GetDataArray(dataArrayStrandCount);

		CICEAttributeDataArray2DVector3f dataArrayStrandPosition;
		oGeom.GetICEAttributeFromName(L"StrandPosition").GetDataArray2D(dataArrayStrandPosition);

		for (ULONG i = 0; i < dataArrayPosition.GetCount(); i++)
		{
			f << VectorToString(MATH::CVector3f(dataArrayPosition[i])) + "\n";

			//TODO
			for (LONG j = 0; j < dataArrayStrandCount[0]; j++)
			{
				//f << VectorToString(dataArrayStrandPosition[i][j]) + "\n";
			}

			f << "\n";
		}

		f.close();
	}
예제 #4
0
/*
=======================================================================================================================================
ObeliskInit

Setup entity for team base model/obelisk model.
=======================================================================================================================================
*/
void ObeliskInit(gentity_t *ent) {
	trace_t tr;
	vec3_t dest;

	ent->s.eType = ET_TEAM;

	VectorSet(ent->r.mins, -15, -15, 0);
	VectorSet(ent->r.maxs, 15, 15, 87);

	if (ent->spawnflags & 1) {
		// suspended
		G_SetOrigin(ent, ent->s.origin);
	} else {
		// mappers like to put them exactly on the floor, but being coplanar will sometimes show up as starting in solid, so lif it up one pixel
		ent->s.origin[2] += 1;
		// drop to floor
		VectorSet(dest, ent->s.origin[0], ent->s.origin[1], ent->s.origin[2] - 4096);
		trap_Trace(&tr, ent->s.origin, ent->r.mins, ent->r.maxs, dest, ent->s.number, MASK_SOLID);

		if (tr.startsolid) {
			ent->s.origin[2] -= 1;
			G_Printf("SpawnObelisk: %s startsolid at %s\n", ent->classname, VectorToString(ent->s.origin));

			ent->s.groundEntityNum = ENTITYNUM_NONE;

			G_SetOrigin(ent, ent->s.origin);
		} else {
			// allow to ride movers
			ent->s.groundEntityNum = tr.entityNum;
			G_SetOrigin(ent, tr.endpos);
		}
	}
}
예제 #5
0
void CGridCgiSampleApplication::OnJobDone(CGridClient& grid_client,
                                          CGridCgiContext& ctx)
{

    CNcbiIstream& is = grid_client.GetIStream();
    int count;
                
    // Get the result
    m_Doubles.clear();
    is >> count;
    for (int i = 0; i < count; ++i) {
        if (!is.good()) {
            ERR_POST( "Input stream error. Index : " << i );
            break;
        }
        double d;
        is >> d;
        m_Doubles.push_back(d);
    }

    // Render the result page
    CHTMLText* inp_text = new CHTMLText(
            "<p/>Job is done.<br/>"
            "<p>Result received : <@OUTPUT_DATA@> <br/>"
            "<INPUT TYPE=\"submit\" NAME=\"Submit new Data\" "
                                   "VALUE=\"Submit new Data\">");
    ctx.GetHTMLPage().AddTagMap("VIEW", inp_text);
    CHTMLPlainText* idoubles = new CHTMLPlainText(VectorToString(m_Doubles));
    ctx.GetHTMLPage().AddTagMap("OUTPUT_DATA",idoubles);
}
예제 #6
0
void CGridCgiSampleApplication::OnJobSubmitted(CGridCgiContext& ctx)
{   
    // Render a report page
    CHTMLText* inp_text = new CHTMLText(
               "<p/>Input Data : <@INPUT_DATA@><br/>"
               "<INPUT TYPE=\"submit\" NAME=\"Check Status\" VALUE=\"Check Status\">");
    ctx.GetHTMLPage().AddTagMap("VIEW", inp_text);
    CHTMLPlainText* idoubles = new CHTMLPlainText(VectorToString(m_Doubles));
    ctx.GetHTMLPage().AddTagMap("INPUT_DATA", idoubles);
}
예제 #7
0
/*QUAKED func_timer (0.3 0.1 0.6) (-8 -8 -8) (8 8 8) START_ON
This should be renamed trigger_timer...
Repeatedly fires its targets.
Can be turned on or off by using.

"wait"			base time between triggering all targets, default is 1
"random"		wait variance, default is 0
so, the basic time between firing is a random time between
(wait - random) and (wait + random)

*/
void SP_func_timer(gentity_t *self) {

	G_SpawnFloat("random", "1", &self->random);
	G_SpawnFloat("wait", "1", &self->wait);

	self->use = Use_Func_Timer;
	self->think = Func_Timer_Think;

	if (self->random >= self->wait) {
		self->random = self->wait - FRAMETIME;
		G_Printf("func_timer at %s has random >= wait\n", VectorToString(self->s.origin));
	}

	if (self->spawnflags & 1) {
		self->nextthink = level.time + FRAMETIME;
		self->activator = self;
	}

	self->r.svFlags = SVF_NOCLIENT;
}
/**
 *
 * return a vector of seed points for the given rational
 *
 **/
std::vector<avtVector> GetSeeds( avtPoincareIC *poincare_ic,
                                 avtVector &point1,
                                 avtVector &point2,
                                 double maxDistance )
{
  std::vector<avtVector> puncturePoints;

  FieldlineLib fieldlib;
  fieldlib.getPunctures(poincare_ic->points, avtVector(0, 1, 0), puncturePoints);

  unsigned int toroidalWinding = poincare_ic->properties.toroidalWinding;
  unsigned int windingGroupOffset = poincare_ic->properties.windingGroupOffset;
  
  // Calculate angle size for each puncture point and find the one
  // that forms the largest angle (i.e. flattest portion of the
  // surface).
  int nSeeds = 0;
  double maxAngle = 0;
  unsigned int best_index = 0;

  unsigned int best_one_less;
  unsigned int best_one_more;

  bool twoPts = false;
  for( int i=0; i<toroidalWinding; ++i )
  {
    unsigned int one_less = (i-windingGroupOffset+toroidalWinding) % toroidalWinding;
    unsigned int one_more = (i+windingGroupOffset+toroidalWinding) % toroidalWinding;
    
    if (one_less == one_more)
      {
        best_index = i;
        best_one_more = one_more;
        twoPts = true;
        break;
      }
    
    if (3 <= RATIONAL_DEBUG)
      cerr << "Line: "<<__LINE__<<" wgo: "<<windingGroupOffset<<", ix-1: "<<one_less<<", ix: "<<i<<", ix+1: " <<one_more<<std::endl;

    avtVector pt0 = puncturePoints[one_less];
    avtVector pt1 = puncturePoints[i];
    avtVector pt2 = puncturePoints[one_more];

    // Save the maximum angle angle and the index of the puncture point.
    double angle = GetAngle( pt0, pt1, pt2 );
    if (maxAngle < angle)
    {     
      maxAngle = angle;
      best_index = i;

      best_one_less = one_less;
      best_one_more = one_more;
    }
  } 

 // Get circle equation 
  avtVector pt0,pt1,pt2;
  if (twoPts)
    {
       pt0 = puncturePoints[best_index];
       pt2 = puncturePoints[best_one_more];
       if (1 <= RATIONAL_DEBUG)
        cerr <<"Line: "<<__LINE__<< " 2 Rational Pts:\n"
             <<VectorToString(pt0)<<"\n"
             <<VectorToString(pt2)<<"\n";
       avtVector midpt = pt0 + 0.5 * (pt2-pt0);
       avtVector cx = (pt2-pt0).cross(avtVector(0,1,0));
       avtVector newpt = midpt + .5*cx;
       if (1 <= RATIONAL_DEBUG)
        cerr <<"Line: "<<__LINE__<< " 2 New Pts:\n"
             <<VectorToString(midpt)<<"\n"
             <<VectorToString(newpt)<<"\n";

       pt1 = newpt;
    }
  else
    {

      // Find the circle that intersects the three punctures points which
      // approximates the cross section of the surface.
      
      // Get circle equation 
      pt0 = puncturePoints[best_one_less];
      pt1 = puncturePoints[best_index];
      pt2 = puncturePoints[best_one_more];
      if (1 <= RATIONAL_DEBUG)
        cerr <<"Line: "<<__LINE__<< " Rational Pts:\n"
             <<VectorToString(pt0)<<"\n"
             <<VectorToString(pt1)<<"\n"
             <<VectorToString(pt2)<<"\n";
    }

  point1 = pt1; //for future reference
  point2 = pt2;
  
  if (1 <= RATIONAL_DEBUG)
    cerr <<"Line: "<<__LINE__<< " New seeds between:\n"
         <<VectorToString(point1)<<"\n"
         <<VectorToString(point2)<<"\n";
  
  // Center of the circle
  /////*********** Find The Circle Using Three Points******************///      
  double ax,ay,bx,by,cx,cy,x1,y11,dx1,dy1,x2,y2,dx2,dy2,ox,oy,dx,dy,radius;
  ax = pt0[0]; ay = pt0[2];
  bx = pt1[0]; by = pt1[2];
  cx = pt2[0]; cy = pt2[2];      
  x1 = (bx + ax) / 2;
  y11 = (by + ay) / 2;
  dy1 = bx - ax;
  dx1 = -(by - ay);      
  x2 = (cx + bx) / 2;
  y2 = (cy + by) / 2;
  dy2 = cx - bx;
  dx2 = -(cy - by);      
  ox = (y11 * dx1 * dx2 + x2 * dx1 * dy2 - x1 * dy1 * dx2 - y2 * dx1 * dx2)/ (dx1 * dy2 - dy1 * dx2);
  oy = (ox - x1) * dy1 / dx1 + y11;      
  dx = ox - ax;
  dy = oy - ay;
  radius = sqrt(dx * dx + dy * dy);     
  
  avtVector center(ox,0,oy);
  
  // Get the number of points needed to cover the range between the two
  // the puncture points.
  double dist = (pt2 - pt1).length();
  nSeeds = dist / maxDistance;
  if( dist > (double) nSeeds * maxDistance )
    ++nSeeds;
  double angle =GetAngle(point1, center, point2);
  
  // Add seeds stretching between two of the puncture points.
  std::vector<avtVector> seedPts;
  seedPts.resize( nSeeds );
  if (1 <= RATIONAL_DEBUG)
    std::cerr <<"Line: "<<__LINE__
              << " \ncenter: " << center 
              << " \nradius: " << radius
              << " \nnSeeds: " << nSeeds
              << " \nAngle: " << angle
              << std::endl;
  for( double i=0; i<nSeeds; ++i)
    {
      double t = i / nSeeds;
      avtVector X = center + (std::sin((1-t) * angle ) * (point1-center) + std::sin(t * angle) * (point2-center)) / std::sin(angle);
      X[1] = Z_OFFSET;
      
      seedPts[i] = X;
      
      if (3 <= RATIONAL_DEBUG)
        cerr << "New Seed: "<<VectorToString(X) << std::endl;
    }
  
  return seedPts;  
}
bool PrepareToMinimize(avtPoincareIC *poincare_ic, avtVector &newPt, bool &cbGTba)
{
  // Have bracketed the minimum
  Vector xzplane(0,1,0);
  FieldlineLib fieldlib;
  avtPoincareIC *_a = poincare_ic->a_IC;
  avtPoincareIC *_b = poincare_ic;
  avtPoincareIC *_c = poincare_ic->c_IC;        
  std::vector<avtVector> a_puncturePoints;
  std::vector<avtVector> b_puncturePoints;
  std::vector<avtVector> c_puncturePoints;
  fieldlib.getPunctures(_a->points,xzplane,a_puncturePoints);
  fieldlib.getPunctures(_b->points,xzplane,b_puncturePoints);
  fieldlib.getPunctures(_c->points,xzplane,c_puncturePoints);
                
  // Need to get distances for each a, b & c
  int a_i = FindMinimizationIndex(_a);
  int b_i = FindMinimizationIndex(_b);
  int c_i = FindMinimizationIndex(_c);

  _a->properties.searchState = FieldlineProperties::MINIMIZING_X0;
  _c->properties.searchState = FieldlineProperties::MINIMIZING_X3;
  _a->properties.analysisMethod = FieldlineProperties::RATIONAL_MINIMIZE;
  _c->properties.analysisMethod = FieldlineProperties::RATIONAL_MINIMIZE;
  _a->properties.rationalPt1 =_b->properties.rationalPt1;
  _a->properties.rationalPt2 =_b->properties.rationalPt2;
              
  double bx_ax,cx_bx;
  double a_x,a_z,b_x,b_z,c_x,c_z;
  a_x = a_puncturePoints[a_i][0];
  a_z = a_puncturePoints[a_i][2];
  b_x = b_puncturePoints[b_i][0];
  b_z = b_puncturePoints[b_i][2];
  c_x = c_puncturePoints[c_i][0];
  c_z = c_puncturePoints[c_i][2];
  bx_ax = PythDist(a_puncturePoints[a_i],b_puncturePoints[b_i]);
  cx_bx = PythDist(b_puncturePoints[b_i],c_puncturePoints[c_i]);
                
  avtVector va = a_puncturePoints[a_i];
  avtVector vb = b_puncturePoints[b_i];
  avtVector vc = c_puncturePoints[c_i];

  if (3 <= RATIONAL_DEBUG)
    {
      std::cerr<<"Line: "<<__LINE__<<"Prepare to minimize: "<<"\n\t"<<VectorToString(a_puncturePoints[a_i])<<"\n\t"<<VectorToString(b_puncturePoints[b_i])<<"\n\t"<<VectorToString(c_puncturePoints[c_i])<<"\n";
    }
  double new_x,new_z;
  if (cx_bx > bx_ax)
    {
      cbGTba = true;
      _b->properties.searchState = FieldlineProperties::MINIMIZING_X1;
      _b->properties.analysisMethod = FieldlineProperties::RATIONAL_MINIMIZE;
      
      newPt = vb + golden_C * (vc-vb);

      if (2 <= RATIONAL_DEBUG)
        std::cerr << "LINE " << __LINE__ << " New Minimization pt:\t"<<VectorToString(newPt)<< std::endl; 
    }
  else
    {
      cbGTba = false;
      _b->properties.searchState = FieldlineProperties::MINIMIZING_X2;
      _b->properties.analysisMethod = FieldlineProperties::RATIONAL_MINIMIZE;
      
      newPt = vb + golden_C * (va-vb);
      
      if (2 <= RATIONAL_DEBUG)   
        std::cerr << "LINE " << __LINE__  << " New Minimization pt:\t"<< VectorToString(newPt) << std::endl; 
    }

  newPt[1] = Z_OFFSET;

    return true;
}
예제 #10
0
////////////////////////////////////////////////////////////////////////
// DumpColumn
//
////////////////////////////////////////////////////////////////////////
void DumpColumn
	(
	DBBINDING*		pBinding,
	void*			pData
	)
{
    ASSERT(pBinding && pData);

	void*	p = NULL;
	BOOL    fIsUnicode = TRUE;
	WCHAR	wszBuffer[MAX_QUERY_LEN];
	
	HRESULT hr = S_OK;
	VARIANT* pvVariant = NULL;
	IUnknown* pIUnknown = NULL;
	void* pByRef = NULL;
    
	// Pretty print a column.
	// May have different type of binding.

	DBSTATUS dwStatus = STATUS_BINDING(*pBinding, pData);
	DBLENGTH dwLength = LENGTH_BINDING(*pBinding, pData);

	DBTYPE wType = pBinding->wType;

	switch(dwStatus)
	{
		case DBSTATUS_S_ISNULL:
			dwLength = 0;
			break;
	
		case DBSTATUS_S_OK:
		case DBSTATUS_S_TRUNCATED:
			switch(wType)
			{
				case DBTYPE_BSTR:
				case DBTYPE_WSTR:
					// We have a string in our buffer, so use it.
					p = &VALUE_BINDING(*pBinding, pData);
					dwLength = wcslen((WCHAR*)p);
					break;

				case DBTYPE_STR:
					// We have a string in our buffer, so use it.
					p = &VALUE_BINDING(*pBinding, pData);
					dwLength = strlen((CHAR*)p);
					fIsUnicode = FALSE;
					break;

				case DBTYPE_VARIANT:
					// We have a variant in our buffer, so convert to string.
					pvVariant = (VARIANT*)&VALUE_BINDING(*pBinding, pData);
					wType = V_VT(pvVariant);

					//VariantChangeTypeEx seems to handle most types,
					TESTC(VariantToString(pvVariant, wszBuffer, MAX_QUERY_LEN, FALSE));
					p = wszBuffer;
					break;

				case DBTYPE_HCHAPTER:
				{
					HCHAPTER hChapter = (HCHAPTER)VALUE_BINDING(*pBinding, pData);
					swprintf(wszBuffer, L"%lu", hChapter);
					p = wszBuffer;	
					break;
				}

				case DBTYPE_IUNKNOWN:
				case DBTYPE_IUNKNOWN | DBTYPE_BYREF:
				{
					//It's possible that this object supports a storage object
					//If so, read all the data from the Storage Object and dump it
					//Otherwise just output the actual ptr					
					static WCHAR s_rgchByteHex[] = L"0123456789ABCDEF";
					
					ULONG cBytesRead = 0;
					ULONG ulMaxSize = MAX_QUERY_LEN / 2;
					BYTE* pbBuffer = (BYTE*)PROVIDER_ALLOC(ulMaxSize);
					WCHAR* pch = wszBuffer;

					p = wszBuffer;
					pIUnknown = (IUnknown*)VALUE_BINDING(*pBinding, pData);
					if(wType & DBTYPE_BYREF)
					{
						pByRef = (void*)VALUE_BINDING(*pBinding, pData);
						pIUnknown = *(IUnknown**)pByRef;
					}

					hr = StorageRead(IID_IUnknown, pIUnknown, pbBuffer, ulMaxSize, &cBytesRead);
						
					if (hr == S_OK || hr == S_FALSE)
					{
						// Convert the byte buffer to string.
						for (BYTE *pb = pbBuffer; cBytesRead ;cBytesRead--, pb++)
						{
							*pch++ = s_rgchByteHex[*pb >> 4];
							*pch++ = s_rgchByteHex[*pb & 0x0F];							
						}
						*pch = L'\0';											
					}
					else
					{
						swprintf(wszBuffer, L"%p", pIUnknown);
					}

					SAFE_FREE(pbBuffer);
					break;
				}
		
				default:
					if(wType & DBTYPE_VECTOR)
					{
						DBVECTOR* pVector = (DBVECTOR*)&VALUE_BINDING(*pBinding, pData);
						hr = VectorToString(pVector, wType, wszBuffer, MAX_QUERY_LEN);
						p = wszBuffer;
					}
					else if(wType & DBTYPE_ARRAY)
					{
						SAFEARRAY* pSafeArray = *(SAFEARRAY**)&VALUE_BINDING(*pBinding, pData);
						hr = SafeArrayToString(pSafeArray, wType, wszBuffer, MAX_QUERY_LEN);
						p = wszBuffer;
					}
					else
					{
						p = L"??? Unknown Type ???";
						dwLength = 0;
					}
					break;
			}
			break;

		default:
	        p = L"??? Unknown Status ???";
			dwLength = 0;
			break;
    };