Example #1
0
template<class T> void Convert_To_Tetrahedralized_Volume( tetgenio& out, 
                                                          TETRAHEDRALIZED_VOLUME<T>& volume )
{
    ARRAY<VECTOR<T,3> > X;
    for( int i=0; i < out.numberofpoints; i++){
        VECTOR<T,3> p;
        p.x = out.pointlist[ i*out.mesh_dim + 0 ];
        p.y = out.pointlist[ i*out.mesh_dim + 1 ];
        p.z = out.pointlist[ i*out.mesh_dim + 2 ];
        X.Append(p);
        //LOG::cout << "V" << i+1 << " : " << p << std::endl;
    }

    ARRAY<VECTOR<int,4> > elements;
    for( int i=0; i < out.numberoftetrahedra; i++){
        VECTOR<int,4> e;
        e(1) = out.tetrahedronlist[ i*out.numberofcorners + 0 ];
        e(2) = out.tetrahedronlist[ i*out.numberofcorners + 1 ];
        e(3) = out.tetrahedronlist[ i*out.numberofcorners + 2 ];
        e(4) = out.tetrahedronlist[ i*out.numberofcorners + 3 ];
        elements.Append(e);
        //LOG::cout << "T" << i+1 << " : " << e << std::endl;
    }

    int m = X.m;
    int n = elements.m;

    volume.mesh.Initialize_Mesh(m,elements);
    volume.particles.array_collection->Resize(m);
    volume.particles.X=X;
}
bool CHotKeys::FindFirstConflict(ARRAY& keys, INT_PTR* pX, INT_PTR* pY)
{
	bool bConflict = false;
	INT_PTR i, j;
	INT_PTR count = keys.GetSize();
	DWORD key;
	for(i = 0; i < count && !bConflict; i++)
	{
		key = keys.ElementAt(i);
		// only check valid keys
		if(key == 0)
			continue;

		// scan the array for a duplicate
		for(j = i+1; j < count; j++ )
		{
			if(keys.ElementAt(j) == key)
			{
				bConflict = true;
				break;
			}
		}
	}

	if(bConflict)
	{
		if(pX)
			*pX = i-1;
		if(pY)
			*pY = j;
	}

	return bConflict;
}
Example #3
0
void BaseVector :: SetElementVector (const ARRAY<INDEX> & pnum,
				 const BaseVector & elvec)
{
  int i;
  for (i = 1; i <= pnum.Size(); i++)
    (*this)(pnum.Get(i)) = elvec(i);
}
/////////////////////////////////////
// get_visibility()
/////////////////////////////////////
void
HatchingGroupFixed::get_visibility(TAGformat &d)
{
   err_mesg(ERR_LEV_SPAM, "HatchingGroupFixed::get_visibility()"); 

   BMESH *m = _patch->mesh();
   if (LMESH::isa(m))
      m = ((LMESH*)m)->cur_mesh();

   int k, ctr=0;
   ARRAY<int> indices;
   CBface_list& faces = m->faces();

   *d >> indices;

   for (k=0; k<indices.num(); k++)
      {
         HatchingSimplexDataFixed *hsdf =
            HatchingSimplexDataFixed::find(faces[indices[k]]);
         if (!hsdf) 
            {
               hsdf = new HatchingSimplexDataFixed(faces[indices[k]]);
               ctr++;
            }
         hsdf->add(this);
      }

   err_mesg(ERR_LEV_SPAM, "HatchingGroupFixed::get_visibility() - Flagged %d tris and added %d new simplex data.", indices.num(), ctr); 


}
Example #5
0
BOOL DeleteFormats(int parentID, ARRAY& formatIDs)
{	
	if(formatIDs.GetSize() <= 0)
		return TRUE;
		
	try
	{
		//Delete the requested data formats
		INT_PTR count = formatIDs.GetSize();
		for(int i = 0; i < count; i++)
		{
			theApp.m_db.execDMLEx(_T("DELETE FROM Data WHERE lID = %d;"), formatIDs[i]);
		}

		CClip clip;
		if(clip.LoadFormats(parentID))
		{
			DWORD CRC = clip.GenerateCRC();

			//Update the main table with new size
			theApp.m_db.execDMLEx(_T("UPDATE Main SET CRC = %d WHERE lID = %d"), CRC, parentID);
		}
	}
	CATCH_SQLITE_EXCEPTION
		
	return TRUE;
}
Example #6
0
void BaseVector :: GetElementVector (const ARRAY<INDEX> & pnum,
				 BaseVector & elvec) const
{
  int i;
  for (i = 1; i <= pnum.Size(); i++)
    elvec(i) = (*this)(pnum.Get(i));
}
Example #7
0
void CQListCtrl::LoadCopyOrCutToClipboard()
{
	ARRAY arr;
	GetSelectionItemData(arr);
	INT_PTR count = arr.GetSize();
	if(count <= 0)
		return;
	
	CProcessPaste paste;
	
	//Don't send the paste just load it into memory
	paste.m_bSendPaste = false;
		
	if(count > 1)
		paste.GetClipIDs().Copy(arr);
	else
		paste.GetClipIDs().Add(arr[0]);
	
	//Don't move these to the top
	BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
	g_Opt.m_bUpdateTimeOnPaste = FALSE;

	paste.DoPaste();

	g_Opt.m_bUpdateTimeOnPaste = bItWas;
}
Example #8
0
 void Flags :: SetFlag (const char * name, const ARRAY<double> & val)
 {
   ARRAY<double> * numarray = new ARRAY<double>;
   for (int i = 1; i <= val.Size(); i++)
     numarray->Append (val.Get(i));
   numlistflags.Set (name, numarray);
 }
Example #9
0
void Vector :: AddElementVector (const ARRAY<INDEX> & pnum,
				 const BaseVector & elvec)
{
  int i;
  const Vector & helvec = elvec.CastToVector();
  for (i = 1; i <= pnum.Size(); i++)
    Elem(pnum.Get(i)) += helvec.Get(i);
}
Example #10
0
void Vector :: GetElementVector (const ARRAY<INDEX> & pnum,
				 BaseVector & elvec) const
{
  int i;
  Vector & helvec = elvec.CastToVector();
  for (i = 1; i <= pnum.Size(); i++)
    helvec.Elem(i) = Get(pnum.Get(i));
}
Example #11
0
void LineSeg<D> :: GetRawData (ARRAY<double> & data) const
{
  data.Append(2);
  for(int i=0; i<D; i++)
    data.Append(p1[i]);
  for(int i=0; i<D; i++)
    data.Append(p2[i]);
}
Example #12
0
void
UVdata::split(CEdgeStrip& strip)
{
   ARRAY<Bvert_list> chains;
   strip.get_chains(chains);
   for (int i=0; i<chains.num(); i++)
      split_chain(chains[i]);
}
Example #13
0
void Primitive :: GetTangentialSurfaceIndices (const Point<3> & p, 
					       ARRAY<int> & surfind, double eps) const
{
  for (int j = 0; j < GetNSurfaces(); j++)
    if (fabs (GetSurface(j).CalcFunctionValue (p)) < eps)
      if (!surfind.Contains (GetSurfaceId(j)))
	surfind.Append (GetSurfaceId(j));
}
Example #14
0
void Intersection (const FlatArray<T> & in1, const FlatArray<T> & in2, const FlatArray<T> & in3,
		   ARRAY<T> & out)
{
  out.SetSize(0);
  for(int i=0; i<in1.Size(); i++)
    if(in2.Contains(in1[i]) && in3.Contains(in1[i]))
      out.Append(in1[i]);
}
Example #15
0
 /// array copy 
 explicit ARRAY (const ARRAY<T> & a2)
   : FlatArray<T, BASE> (a2.Size(), a2.Size() ? new T[a2.Size()] : 0)
 {
   allocsize = this->size;
   ownmem = 1;
   for (int i = BASE; i < this->size+BASE; i++)
     (*this)[i] = a2[i];
 }
Example #16
0
void Solver::QPSolve(ARRAY<2, double>& a, ARRAY<1, double>& b, ARRAY<1, double>& f) {
    int n = f.dim(1);
    f.Fill(0);
    ARRAY<1, double> c = b;
    ARRAY<1, double> delta_f(n), delta_a(n);
    set<int> C, NC;
    set<int> ad_minus;
    for (int i = 1; i <= n; ++i) {
        if (c(i) < -1e-4) {
            ad_minus.insert(i);
        }
    }
    
    while (!ad_minus.empty()) {
        set<int>::iterator it = ad_minus.begin();
        int d = *it;
        NC.erase(d);
        while (true) {
            fdirection(d, a, C, delta_f, delta_a);
            pair<double, int> sj = maxstep(f,c,delta_f,delta_a,C,NC,d);
            if (sj.first > 1e20) {
                return;
            }
            for (set<int>::iterator it = C.begin(); it != C.end(); ++it)
                if (*it != d)
                    f(*it) += sj.first * delta_f(*it);
            f(d) += sj.first * delta_f(d);
            for (int i = 1; i <= n; ++i) {
                c(i) += delta_a(i) * sj.first;
                if (c(i) < -1e-4) {
                    ad_minus.insert(i);
                } else {
                    if (i == d) {
                        sj.second = d;
                        NC.erase(d);
                    }
                    ad_minus.erase(i);
                }
            }
            it = C.find(sj.second);
            if (it != C.end()) {
                NC.insert(*it);
                C.erase(it);
            } else {
                it = NC.find(sj.second);
                if (it != NC.end()) {
                    C.insert(*it);
                    NC.erase(it);
                } else {
                    C.insert(d);
                    ad_minus.erase(d);
                    break;
                }
            }
        }
    }
}
//#####################################################################
// Function Compute_Level_Set_Helper
//#####################################################################
template<class T> void LEVELSET_MAKER_UNIFORM_2D<T>::
Compute_Level_Set_Helper(const TV_INT& index,T next,ARRAY<TV_INT>& next_todo,ARRAY<T,TV_INT>& phi)
{
    if(!phi.Valid_Index(index)) return;
    T& p=phi(index);
    if(p!=FLT_MAX) return;
    p=next;
    next_todo.Append(index);
}
Example #18
0
 //get all trigs:
 int GetTrig(int i) const
 {
     if (i <= charttrigs->Size()) {
         return charttrigs->Get(i);
     }
     else {
         return outertrigs->Get(i-charttrigs->Size());
     }
 }
Example #19
0
void *NMultiSet(MULTI *ma, int *k, void *d) {
  int i, j, m = 0, h;
  MDATA *pt = NULL;
  ARRAY *a;
  DATA *p, *p0 = NULL;

  if (ma->maxelem > 0 && ma->numelem >= ma->maxelem) {
    NMultiFreeData(ma);
    ma->numelem = 0;
  }
  h = Hash2(k, ma->ndim, 0, ma->ndim);
  a = &(ma->array[h]);
  if (a->dim == 0) {
    a->data = (DATA *) malloc(sizeof(DATA));
    a->data->dptr = malloc(a->bsize);
    InitMDataData(a->data->dptr, a->block);
    a->data->next = NULL;
    pt = (MDATA *) a->data->dptr;
  } else {
    p = a->data;
    i = a->dim;
    j = 0;
    while (p) {
      pt = (MDATA *) p->dptr;
      for (m = 0; m < a->block && j < i; j++, m++) {
	if (memcmp(pt->index, k, ma->isize) == 0) {
	  if (d) {
	    memcpy(pt->data, d, ma->esize);
	  }
	  return pt->data;
	}
	pt++;
      }
      p0 = p;
      p = p->next;
    }  
    if (m == a->block) {
      p0->next = (DATA *) malloc(sizeof(DATA));
      p = p0->next;
      p->dptr = malloc(a->bsize);
      InitMDataData(p->dptr, a->block);
      p->next = NULL;
      pt = (MDATA *) p->dptr;
    }
  }

  ma->numelem++;
  pt->index = malloc(ma->isize);
  memcpy(pt->index, k, ma->isize);
  pt->data = malloc(ma->esize);
  if (a && a->InitData) a->InitData(pt->data, 1);
  if (d) memcpy(pt->data, d, ma->esize);
  (a->dim)++;

  return pt->data;
}
Example #20
0
void CQListCtrl::GetSelectionIndexes(ARRAY &arr)
{
	arr.RemoveAll();
	
	POSITION pos = GetFirstSelectedItemPosition();
	while (pos)
	{
		arr.Add(GetNextSelectedItem(pos));
	}
}
Example #21
0
void QickSort (const ARRAY<double> & values,
	       ARRAY<int> & order)
{
  int i, n = values.Size();
  order.SetSize (n);
  for (i = 1; i <= n; i++)
    order.Elem(i) = i;

  QickSortRec (values, order, 1, order.Size());
}
Example #22
0
  void Flags :: SetFlag (const char * name, const ARRAY<char*> & val)
  {
    ARRAY<char*> * strarray = new ARRAY<char*>;
    for (int i = 1; i <= val.Size(); i++)
      {
	strarray->Append (new char[strlen(val.Get(i))+1]);
	strcpy (strarray->Last(), val.Get(i));
      }
    strlistflags.Set (name, strarray);
  }
//#####################################################################
// Function Build_Mesh
//#####################################################################
template<class T> void RED_GREEN_GRID_3D<T>::
Build_Mesh(TETRAHEDRON_MESH& tetrahedron_mesh,const ARRAY<T>* phi,ARRAY<int>& cell_to_tetrahedron_mapping,ARRAY<int>* node_to_particle_mapping) const
{
    tetrahedron_mesh.Clean_Memory();
    cell_to_tetrahedron_mapping.Clean_Memory();cell_to_tetrahedron_mapping.Resize(number_of_cells);
    if(node_to_particle_mapping){node_to_particle_mapping->Clean_Memory();node_to_particle_mapping->Resize(number_of_nodes);}
    for(int i=1;i<=uniform_grid.counts.x;i++) for(int j=1;j<=uniform_grid.counts.y;j++) for(int ij=1;ij<=uniform_grid.counts.z;ij++) if(elements(i,j,ij))
        elements(i,j,ij)->Build_Tetrahedron_Mesh(tetrahedron_mesh,phi,cell_to_tetrahedron_mapping,node_to_particle_mapping);
    tetrahedron_mesh.number_nodes=node_to_particle_mapping?node_to_particle_mapping->Max():number_of_nodes;
}
Example #24
0
inline
Wpt
center (Wpt_list& pts, ARRAY<int>& N)
{
   Wpt ret = Wpt(0);
   for (int i = 0; i < N.num(); i++) {
      ret += pts[N[i]];
   }
   return ret / N.num();
}
Example #25
0
void SplineSeg3<D> :: GetRawData (ARRAY<double> & data) const
{
  data.Append(3);
  for(int i=0; i<D; i++)
    data.Append(p1[i]);
  for(int i=0; i<D; i++)
    data.Append(p2[i]);
  for(int i=0; i<D; i++)
    data.Append(p3[i]);
}
Example #26
0
File: main.cpp Project: rveens/CPP2
void week3b()
{
	ARRAY<int> lijst; // maakt een array met nul elementen
	lijst.append(13); // voegt toe aan het einde
	lijst[-1] = 12; // voegt toe aan het einde
	int n = lijst.length();
	for(int i = 0; i < n; i++)
	{
	   cout << "lijst[" << i << "]=" << lijst[i] << endl;
	}
	lijst[2] = 14; // moet een exception genereren
}
Example #27
0
void CQListCtrl::GetSelectionItemData(ARRAY &arr)
{
	DWORD dwData;
	int i;
	arr.RemoveAll();
	POSITION pos = GetFirstSelectedItemPosition();
	while (pos)
	{
		i = GetNextSelectedItem(pos);
		dwData = GetItemData(i);
		arr.Add( dwData );
	}
}
int make_chain(ARRAY<NDCZpt*>& V, int (*cmp)(const void*, const void*)) 
{
	int i, j, s = 1; 	NDCZpt *tmp;
	V.sort(cmp);
	for (i=2; i<V.num(); i++) 
   {
      for (j=s; j>=1 ; j--)
         if ((det(NDCvec(*(V[i]) - *(V[j])),	NDCvec(*(V[j-1]) - *(V[j]))) > 0)) break;
		s = j+1;
		tmp = V[s]; V[s] = V[i]; V[i] = tmp;
	}
	return s;
}
//#####################################################################
// Function Command_Prompt_Response
//#####################################################################
template<class T,class RW> void OPENGL_COMPONENT_DEBUG_PARTICLES_2D<T,RW>::
Command_Prompt_Response()
{
    if(!OPENGL_WORLD::Singleton()->prompt_response.empty()){
        std::string command;
        std::istringstream sstream(OPENGL_WORLD::Singleton()->prompt_response);
        sstream>>command;
        if(command=="s"){
            ARRAY<int> indices;
            int index;
            while(sstream>>index) indices.Append(index);
            opengl_particles.Clear_Selection();
            opengl_particles.Select_Points(indices);}}
//#####################################################################
// Function Cubic_MN_Weights
//#####################################################################
template<class T,class T2> ARRAY<T> CUBIC_MN_INTERPOLATION<T,T2>::
Cubic_MN_Weights(const T alpha) const
{
    T alpha2=alpha*alpha;
    T alpha3=alpha2*alpha;
    ARRAY<T> weights;
    weights.Append(-alpha3/2.+alpha2-.5*alpha); //f_k-1
    weights.Append(alpha3/2.-5*alpha2/2.+1); //f_k
    weights.Append(-alpha3/2.+2*alpha2+alpha/2.); //f_k+1
    weights.Append(alpha3/2.-alpha2/2.);  //f_k+2
    for(int i=1;i<=weights.m;i++) weights(i)=max((T)0.,min((T)1.,weights(i)));
    return weights;
}