/*
Check if three 3d points are colinera. I've been a slack and use the difference in the
directional unit vectors as the indicator.
*/
float
_colinear(const CParticleF& p, const CParticleF& q, const CParticleF& r)
{
	CParticleF u = UnitVector(Difference(q, p));
	CParticleF v = UnitVector(Difference(r, p));
	return Distance(u, v);
}
void OpenSMOKE_KPP_SingleReactor::ODESystemContinousReactor(BzzVector &omega, double t, BzzVector &domega)
{
	if (data_->PredictorCorrector_DeferredConvection() == true || 
		data_->networkStatus() == KPP_NETWORK_STATUS_SEQUENTIAL_CSTR )
	{
		// Formation rates
		kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
		Product(volume_, R_, &RV_);

		// mass*domegaj = -mOut*omegaj + mjIn + Rj*V
		Product(-M_, omega, &domega);
		Sum(&domega, RV_);
		Sum(&domega, mInTot_);
		domega /= mass_;
	}
	else
	{
		// Formation rates
		kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
		Product(volume_, R_, &RV_);

		// mass*domegaj = -mOut*omegaj(n) + mjIn + Rj*V
		domega = RV_;
		Sum(&domega, mInTot_);
		Difference(&domega, mOut_x_omega_old_);
		domega /= mass_;
	}
}
// Colonne
float colonne(in vec3 p, in vec3 a, in vec3 b, float rayon, float e, float R){
	float d;
	float offset = 0.28;
	float offsetCube = 0.15;
	d = cylindre(p, a, b, rayon, e, R);
	
	for(float i=0.0;i<12.0; i++){
        vec3 pos = vec3(cos(i*3.14/6.0)*(rayon+rayon*offset), 0.0, sin(i*3.14/6.0)*(rayon+rayon*offset) );
        
        vec3 newA = pos + a;//vec3(a.x + cos(i*3.14/6.0)*(rayon+rayon*offset), a.y + 0.0, a.z + sin(i*3.14/6.0)*(rayon+rayon*offset) );
		vec3 newB = pos + b;//vec3(b.x + cos(i*3.14/6.0)*(rayon+rayon*offset), b.y - 0.0, b.z + sin(i*3.14/6.0)*(rayon+rayon*offset) );
		
		d = Difference(d, cylindre( p, newA, newB, rayon/6.0, e, R/6.0 ) );
		
		
	}
    float d2 = disque(p, a-vec3(0,R*0.7,0), normalize(b-a),rayon*1.5, e, R);
    d2 = Blend(d2,disque(p, b+vec3(0,R*0.7,0), normalize(a-b),rayon*1.5, e, R));
    d2 = Blend(d2, cube(p, vec3(a.x, a.y-R, a.z), vec3( (rayon)*4., offsetCube, (rayon)*4. ), e, 0.1 ));
	d2 = Blend(d2, cube(p, vec3(b.x, b.y+R, b.z), vec3( (rayon)*4., offsetCube, (rayon)*4. ), e, 0.1 ));
	
    d = Union(d,d2);
    
	return d;
}
float RageTimer::GetDeltaTime()
{
	const RageTimer Now;
	const float diff = Difference( Now, *this );
	*this = Now;
	return diff;
}
示例#5
0
  std::string HiResTimer::ToHumanReadableString() const {
    timespec t = Difference();

    time_t days = t.tv_sec / 86400;
    t.tv_sec -= days * 86400;
    time_t hours = t.tv_sec / 3600;
    t.tv_sec -= hours * 3600;
    time_t minutes = t.tv_sec / 60;
    t.tv_sec -= minutes * 60;
    time_t seconds = t.tv_sec;

    std::stringstream ss;

    if (days != 0) {
      ss << days << "d ";
    }

    if (hours != 0) {
      ss << hours << "h ";
    }

    if (minutes != 0) {
      ss << minutes << "m ";
    }

    ss << seconds << "s " << t.tv_nsec << "ns";

    return ss.str();
  }
示例#6
0
 std::string HiResTimer::ToString() const {
   timespec t = Difference();
   std::stringstream str;
   str.fill('0');
   str << t.tv_sec << "." << std::setw(9) << t.tv_nsec;
   return str.str();
 }
示例#7
0
int main(int argc, char **argv)
{
	UINT		nCheckPoint;
    BOOL    bDebug = FALSE;
    int     nPort = 8000;
    UINT    nNzcNumber = 0;
    char    ipaddr[64] = {0,};
    int     opt;
    int     ret=0;

    while((opt=getopt(argc, argv, "dhn:p:")) != -1) {
        switch(opt) {
            case 'd': bDebug = TRUE; break;
            case 'p': nPort = (int)strtol(optarg, (char **)NULL, 10); break;
            case 'n': nNzcNumber = strtol(optarg, (char **)NULL, 10); break;
            case 'h':
            default :
                usage(argv[0]);
        }
    }

    if((argc - optind) < 1) {
        usage(argv[0]);
    }
    strncpy(ipaddr, argv[optind], MIN(sizeof(ipaddr)-1, strlen(argv[optind])));

	CheckPoint(&nCheckPoint);
	CDbUploadService svc(nNzcNumber, ipaddr, nPort, bDebug);

	ret = svc.Startup();
	svc.Shutdown();

	Difference(nCheckPoint);
	return ret>0?1:0;
}
示例#8
0
double Distortion(IOSet *s1, IOSet *s2, IOSet *t1, IOSet *t2, RContext *k,int s, int t){
    double dist=0;
  IOSet *diffT = Intersect(t1,t2);
  double n = diffT->Size();
  for(int i=0; i < diffT->Size(); i++){
        RSet *rr = k->GetSet(t,diffT->At(i));
        IOSet *lclInter = Intersect(rr->GetIdxs(),s2);
        IOSet *lclDiff = Difference(s2,lclInter);
        if(lclInter->Size() > 0){
             RSet *fullSub =  rr->GetSubspace(lclInter);
             RSet *subSub = rr->GetSubspace(s1);
             double rangeFull = fullSub->GetMaxElement().second - fullSub->GetMinElement().second;
             double rangeSub =  subSub->GetMaxElement().second - subSub->GetMinElement().second;
             dist += (1+lclDiff->Size())* (1-(rangeSub/rangeFull));
             delete fullSub;
             delete subSub;
        }else{
                dist += (double)(1.0+lclDiff->Size());
        }
        delete lclInter;
        delete lclDiff;
  }
  delete diffT;
  return dist/n;
}
示例#9
0
void
ProgressTracker::SyncNotifyProgress(Progress aProgress,
                                    const nsIntRect& aInvalidRect
                                                  /* = nsIntRect() */)
{
  MOZ_ASSERT(NS_IsMainThread(), "Use mObservers on main thread only");

  // Don't unblock onload if we're not blocked.
  Progress progress = Difference(aProgress);
  if (!((mProgress | progress) & FLAG_ONLOAD_BLOCKED)) {
    progress &= ~FLAG_ONLOAD_UNBLOCKED;
  }

  // XXX(seth): Hack to work around the fact that some observers have bugs and
  // need to get onload blocking notifications multiple times. We should fix
  // those observers and remove this.
  if ((aProgress & FLAG_DECODE_COMPLETE) &&
      (mProgress & FLAG_ONLOAD_BLOCKED) &&
      (mProgress & FLAG_ONLOAD_UNBLOCKED)) {
    progress |= FLAG_ONLOAD_BLOCKED | FLAG_ONLOAD_UNBLOCKED;
  }

  // Apply the changes.
  mProgress |= progress;

  CheckProgressConsistency(mProgress);

  // Send notifications.
  SyncNotifyInternal(mObservers, HasImage(), progress, aInvalidRect);

  if (progress & FLAG_HAS_ERROR) {
    FireFailureNotification();
  }
}
示例#10
0
bool ObjectFromColor(_TCHAR *name, COLORREF color)
{
	if( 0xff000000 & color ) return false;

	const count = 4;
	static const Node nodes[count] = {
		{0xffffff, _T("WALL_CONCRETE")},
		{0x0000ff, _T("WALL")},
		{0x00ff00, _T("WOOD")},
		{0xff0000, _T("WATER")},
	};
 
	int min_d = 128;	// минимальное различие между цветами
	int index = -1;
	for( int i = 0; i < count; i++ )
	{
		int d = Difference(color, nodes[i].color);
		if( d < min_d )
		{
			min_d = d;
			index = i;
		}
	}

	if( -1 != index )
	{
		_tcscpy(name, nodes[index].name);
		return true;
	}

	return false;
}
示例#11
0
void RampToGray::GetBestCandidates (pI_float r, pI_float g, pI_float b, pI_size& index1, pI_size& index2) {

	pI_float score, top_score(0.0f);
	index1 = 0,	index2 = 0;

	for (pI_size lv = 1; lv < _colour_map.size(); ++lv) {
		t_cc cc(_colour_map[lv]);
		score = 1.0f - Difference (r, cc.r);
		score += 1.0f - Difference (g, cc.g);
		score += 1.0f - Difference (b, cc.b);
		if (score > top_score) {
			index2 = index1;
			index1 = lv;
			top_score = score;
		}
	}
} // void RampToGray::GetBestCandidates (pI_byte r, pI_byte g, pI_byte b, pI_size& index1, pI_size& index2)
Difference Normal::difference(float value)
{
    return Difference(
                value - upper,
                value - lower,
                value - average
    );
}
示例#13
0
void Scene::MoveCursorToAdhere(const Edge& edge) {
  Q_CHECK_PTR(cursor_);
  if (const auto adherable = GetAdherableEdge(*cursor_, edge)) {
    if (const auto difference = Difference(*adherable, edge)) {
      cursor_->moveBy(difference->x(), difference->y());
      return;
    }
  }
  Q_UNREACHABLE();
}
示例#14
0
	OpenSMOKEVector<T, IndexPolicy>& OpenSMOKEVector<T, IndexPolicy>::operator-=(OpenSMOKEVector<T, IndexPolicyRHS> const& rval)
	{
		if(dimensions_ != rval.Size())
			ErrorMessage("operator-=(const OpenSMOKEVector<T, IndexPolicy>& rval) Dimension check failure");
		
		if(whoAmI_ == rval.WhoAmI())
			Sub(this);
		else
			Difference(dimensions_, vector_+this->index_, rval.Vector()+rval.Index());
		return *this;
	}
示例#15
0
POINT* convertRectToPoints(RECT rect)
{
	POINT* points = malloc(4 * sizeof(POINT));

	int height = Difference(rect.top, rect.bottom);
	int width = Difference(rect.left, rect.right);

	points[2].x = rect.left;
	points[2].y = height;

	points[3].x = width;
	points[3].y = height;

	points[0].x = rect.left;
	points[0].y = Least(rect.top, rect.bottom);

	points[1].x = width;
	points[1].y = Least(rect.top, rect.bottom);

	return points;
}
示例#16
0
void Diff( Pilha p )
{
    LL linkA, linkB, linkR;

    if ( STACKsize( p ) >= 2 )
    {
        linkA = STACKget(p);
        linkB = STACKget(p);
        linkR = Difference( linkA, linkB );
        STACKput( p, linkR );
    }
}
示例#17
0
int main(){
    struct TIME t1,t2,diff;
    printf("Enter start time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d%d%d",&t1.hours,&t1.minutes,&t1.seconds);
    printf("Enter stop time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d%d%d",&t2.hours,&t2.minutes,&t2.seconds);
    Difference(t1,t2,&diff);
    printf("\nTIME DIFFERENCE: %d:%d:%d - ",t1.hours,t1.minutes,t1.seconds);
    printf("%d:%d:%d ",t2.hours,t2.minutes,t2.seconds);
    printf("= %d:%d:%d\n",diff.hours,diff.minutes,diff.seconds);
    return 0;
}
/*-----------------------------------------------------------------*/
int main(void)
{
    char command;
    struct list_node_s* head_p1 = NULL;
    struct list_node_s* head_p2 = NULL;
    struct list_node_s* head_p3 = NULL;
    /* start with empty list */
    
    command = Get_command();
    while (command != 'q' && command != 'Q') {
        
        head_p1 = Build(head_p1);
        head_p2 = Build(head_p2);
        
        switch (command) {
            case 'u':
            case 'U':
                head_p3 = Union(head_p1, head_p2);
                printf("The union between the two sets is: ");
                Print(head_p3);
                break;
                
            case 'i':
            case 'I':
                head_p3 = Intersect(head_p1, head_p2);
                printf("The intersection of the two sets is: ");
                Print(head_p3);
                break;
                
            case 'd':
            case 'D':
                head_p3 = Difference(head_p1, head_p2);
                printf("The difference between the two sets is: ");
                Print(head_p3);
                break;
                
            default:
                printf("There is no %c command\n", command);
                printf("Please try again\n");
        }
        
        head_p1 = Free_list(head_p1);
        head_p2 = Free_list(head_p2);
        head_p3 = Free_list(head_p3);
        
        command = Get_command();
    }
    
    return 0;
} /* main */
void Vector()
{
  std::cout << "Vector()" << std::endl;
  
  std::vector<float> vec(patchRadius*patchRadius);

  ImageType::Pointer image = ImageType::New();
  CreateImage(image);

  itk::Index<2> center = {{imageSize/2, imageSize/2}};
  itk::ImageRegion<2> centerRegion = GetRegionInRadiusAroundPixel(center, patchRadius);
  std::vector<float> centerDescriptor = MakeDescriptor(centerRegion, image);

  std::vector<std::vector<float> > allDescriptors;

  {
  itk::ImageRegionIterator<ImageType> imageIterator(image, image->GetLargestPossibleRegion());

  while(!imageIterator.IsAtEnd())
    {
    itk::ImageRegion<2> region = GetRegionInRadiusAroundPixel(imageIterator.GetIndex(), patchRadius);
    if(image->GetLargestPossibleRegion().IsInside(region))
      {
      allDescriptors.push_back(MakeDescriptor(region, image));
      }

    ++imageIterator;
    }
  }

  std::cout << "There are " << allDescriptors.size() << " descriptors." << std::endl;
  std::cout << "There are " << allDescriptors[0].size() << " elements per descriptor." << std::endl;
  itk::TimeProbe clock1;

  clock1.Start();
  float totalDifference = 0.0f;
  for(unsigned int outerLoop = 0; outerLoop < numberOfOuterLoops; ++outerLoop)
    {
    for(unsigned int i = 0; i < allDescriptors.size(); ++i)
      {
      totalDifference += Difference(centerDescriptor, allDescriptors[i]);
      }
    }

  clock1.Stop();
  std::cout << "Total time: " << clock1.GetTotal() << std::endl;
  std::cout << "Total difference: " << totalDifference << std::endl;
}
void ITKImage()
{
  std::cout << "ITKImage()" << std::endl;
  
  ImageType::Pointer image = ImageType::New();
  CreateImage(image);

  itk::Index<2> center = {{imageSize/2, imageSize/2}};
  itk::ImageRegion<2> centerRegion = GetRegionInRadiusAroundPixel(center, patchRadius);

  std::vector<itk::ImageRegion<2> > allRegions;

  {
  itk::ImageRegionIterator<ImageType> imageIterator(image, image->GetLargestPossibleRegion());

  while(!imageIterator.IsAtEnd())
    {
    itk::ImageRegion<2> region = GetRegionInRadiusAroundPixel(imageIterator.GetIndex(), patchRadius);
    if(image->GetLargestPossibleRegion().IsInside(region))
      {
      allRegions.push_back(region);
      }
    ++imageIterator;
    }
  }

  itk::TimeProbe clock1;

  clock1.Start();

  float totalDifference = 0.0f;
  for(unsigned int outerLoop = 0; outerLoop < numberOfOuterLoops; ++outerLoop)
    {
    for(size_t regionId = 0; regionId < allRegions.size(); ++regionId)
      {
      totalDifference += Difference(allRegions[regionId], centerRegion, image);
      }
    }

  clock1.Stop();
  std::cout << "Total time: " << clock1.GetTotal() << std::endl;
  std::cout << "Total difference: " << totalDifference << std::endl;
  
}
float bassin(vec3 p)
{
	//sol avec un trou
 	float v = cylindre(p, vec3(0,-5,0), vec3(0,-3,0), 10.0,1.0,1.0);
    v = Difference(v, cylindre(p, vec3(0,-4,0), vec3(0,-3,0), 5.0,1.0,1.0));
    
	//vague dans le trou
	v = Blend(v, vague(warp(vec3(p)), vec3(0,-3.5,0), 5.5, 0.15, 0.15,1.0,1.0));
    
	//piliers
    v = Union(v, colonne(p, vec3(8,-1.8,0), vec3(8,3.0,0), 0.5, 1.0, 0.6)); 
    v = Union(v, colonne(p, vec3(0,-1.8,8), vec3(0,3.0,8), 0.5, 1.0, 0.6)); 
    v = Union(v, colonne(p, vec3(-8,-1.8,0), vec3(-8,3.0,0), 0.5, 1.0, 0.6)); 
    v = Union(v, colonne(p, vec3(0,-1.8,-8), vec3(0,3.0,-8), 0.5, 1.0, 0.6));
	
	//toit
    v = Union(v, cylindre(p, vec3(0,4.2,0), vec3(0,5,0), 10.0,1.0,1.0));
    
    return v;
}
示例#22
0
void fitWindow(int cellSize, int prevCellSize, WindowDetails* details)
{
	double scale = (double)gCellSize / prevCellSize;

	gWindowHeight = (int)ceil(gWindowHeight*scale);
	gWindowWidth = (int)ceil(gWindowWidth*scale);

	details->Height = gWindowHeight;
	details->Width = gWindowWidth;

	details->BitMapInfo.bmiHeader.biWidth = gWindowWidth;
	details->BitMapInfo.bmiHeader.biHeight = -gWindowHeight;

	RECT adjustedRect = { 0 };
	adjustedRect.bottom = gWindowHeight;
	adjustedRect.right = gWindowWidth;
	AdjustWindowRect(&adjustedRect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE, FALSE);

	SetWindowPos(details->Window, 0, 0, 0, Difference(adjustedRect.right, adjustedRect.left), Difference(adjustedRect.bottom, adjustedRect.top), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

	free(details->BackBuffer);
	details->BackBuffer = (int*)calloc(gWindowHeight*gWindowWidth, sizeof(int));
}
示例#23
0
void
ProgressTracker::SyncNotifyProgress(Progress aProgress,
                                    const nsIntRect& aInvalidRect /* = nsIntRect() */)
{
  MOZ_ASSERT(NS_IsMainThread(), "Use mConsumers on main thread only");

  // Don't unblock onload if we're not blocked.
  Progress progress = Difference(aProgress);
  if (!((mProgress | progress) & FLAG_ONLOAD_BLOCKED)) {
    progress &= ~FLAG_ONLOAD_UNBLOCKED;
  }

  // Apply the changes.
  mProgress |= progress;

  CheckProgressConsistency(mProgress);

  // Send notifications.
  SyncNotifyInternal(mConsumers, !!mImage, progress, aInvalidRect);

  if (progress & FLAG_HAS_ERROR) {
    FireFailureNotification();
  }
}
示例#24
0
int main(void) {
   set_t  *A_p = NULL, *B_p = NULL, *C_p = NULL;
   char   command;

   command = Get_command();
   while (command != 'q' && command != 'Q') {
      A_p = Read_set("A");
      B_p = Read_set("B");
      switch (command) {
         case 'u':
         case 'U':
            C_p = Union(A_p, B_p);
            Print_set(C_p, "C");
            Free_all_sets(&A_p, &B_p, &C_p);
            break;
         case 'i':
         case 'I':
            C_p = Intersection(A_p, B_p);
            Print_set(C_p, "C");
            Free_all_sets(&A_p, &B_p, &C_p);
            break;
         case 'd':
         case 'D':
            C_p = Difference(A_p, B_p);
            Print_set(C_p, "C");
            Free_all_sets(&A_p, &B_p, &C_p);
            break;
         default:
            printf("There is no %c command\n", command);
            printf("Please try again\n");
      } /* switch */
      command = Get_command();
   }  /* while */

   return 0;
}  /* main */
示例#25
0
文件: sets.c 项目: tcsiwula/c_code
/* ========================================================================== */
int main(void)
{
# ifdef DEBUG
    printf("\n\t\t######################################");
    printf("\n\t\t#!!!   Debugger mode turned on.   !!!#");
    printf("\n\t\t#!!!   File: %s               !!!#", __FILE__);
    printf("\n\t\t#!!!   Line: %d.                  !!!#", __LINE__);
    printf("\n\t\t######################################\n\n");
# endif
    struct set_s* a_p = NULL;
    struct set_s* b_p = NULL;
    struct set_s* c_p = NULL;
    struct set_s* C = NULL;
    int asize, bsize, csize;
    asize = bsize = csize = 0;
    char command;
    command = Get_command();

    if(command != 'q' && command != 'Q')
    {
        a_p = Read_set(a_p, &asize, 1);
        b_p = Read_set(b_p, &bsize, 2);
        csize = asize + bsize;
    }

   while (command != 'q' && command != 'Q')
   {
       switch (command)
       {
           case 'u':
           case 'U':
                printf("\n\nFinding the union of the two sets. \n");
                c_p = Union(a_p, asize, b_p, bsize, c_p, csize, C);
                Print(a_p, 1);
                Print(b_p, 2);
                printf("Union: ");
                Print(c_p, 3);
                printf("\n");
                break;
           case 'i':
           case 'I':
               printf("\n\nFinding the intersection of the two sets. \n");
               c_p = Intersection(a_p, asize, b_p, bsize, c_p, csize, C);
               Print(a_p, 1);
               Print(b_p, 2);
               printf("Intersection: ");
               Print(c_p, 3);
               printf("\n");
               break;
           case 'd':
           case 'D':
               printf("\n\nFinding the difference of the two sets. \n");
               c_p = Difference(a_p, asize, b_p, bsize, c_p, csize, C);
               Print(a_p, 1);
               Print(b_p, 2);
               printf("Difference: ");
               Print(c_p, 3);
               printf("\n");
               break;
           case '\n':
               printf("\n$ ");
               break;
           default:
               printf("There is no %c command\n", command);
               printf("Please try aga_pn\n");
       }

       // free lists and reset list sizes.
        a_p = Free_list(a_p);
        b_p = Free_list(b_p);
        c_p = Free_list(c_p);
        C = Free_list(C);
        asize = bsize = csize = 0;

       // get command for operation to perform.
       command = Get_command();

       // read in new lists and update csize.
       if(command != 'q' && command != 'Q')
       {
           a_p = Read_set(a_p, &asize, 1);
           b_p = Read_set(b_p, &bsize, 2);
           csize = asize + bsize;
       }
   }

    return 0;
}  /* main */
示例#26
0
void MemoryMap::diffWith(MemoryMap* other)
{
    _pmemDiff.clear();

    QIODevice* dev = _vmem->physMem();
    QIODevice* otherDev = other->vmem()->physMem();
    if (!otherDev || !dev)
        return;

    assert(dev != otherDev);

    // Open devices for reading, if required
    if (!dev->isReadable()) {
        if (dev->isOpen())
            dev->close();
        assert(dev->open(QIODevice::ReadOnly));
    }
    else
        assert(dev->reset());

    if (!otherDev->isReadable()) {
        if (otherDev->isOpen())
            otherDev->close();
        assert(otherDev->open(QIODevice::ReadOnly));
    }
    else
        assert(otherDev->reset());

    QTime timer;
    timer.start();
    bool wasEqual = true, equal = true;
    quint64 addr = 0, startAddr = 0, length = 0;
    const int bufsize = 1024;
    const int granularity = 16;
    char buf1[bufsize], buf2[bufsize];
    qint64 readSize1, readSize2;
    qint64 done, prevDone = -1;
    qint64 totalSize = qMin(dev->size(), otherDev->size());
    if (totalSize < 0)
        totalSize = qMax(dev->size(), otherDev->size());

    // Compare the complete physical address space
    while (!Console::interrupted() && !dev->atEnd() && !otherDev->atEnd()) {
        readSize1 = dev->read(buf1, bufsize);
        readSize2 = otherDev->read(buf2, bufsize);

        if (readSize1 <= 0 || readSize2 <= 0)
            break;

        qint64 size = qMin(readSize1, readSize2);
        for (int i = 0; i < size; ++i) {
            if (buf1[i] != buf2[i])
                equal = false;
            // We only consider memory chunks of size "granularity"
            if (addr % granularity == granularity - 1) {
                // Memory is equal
                if (equal) {
                    // Add difference to tree
                    if (!wasEqual)
                        _pmemDiff.insert(Difference(startAddr, length));
                }
                // Memory differs
                else {
                    // Start new difference
                    if (wasEqual) {
                        startAddr = addr - (addr % granularity);
                        length = granularity;
                    }
                    // Enlarge difference
                    else
                        length += granularity;
                }
                wasEqual = equal;
            }
            ++addr;
            equal = true;
        }

        done = (int) (addr / (float) totalSize * 100);
        if (prevDone < 0 || (done != prevDone && timer.elapsed() > 500)) {
            Console::out() << "\rComparing memory dumps: " << done << "%" << flush;
            prevDone = done;
            timer.restart();
        }
    }

    // Add last difference, if any
    if (!wasEqual)
        _pmemDiff.insert(Difference(startAddr, length));

    Console::out() << "\rComparing memory dumps finished." << endl;

//    debugmsg("No. of differences: " << _pmemDiff.objectCount());
}
Set<V> Set<V>::operator - (const Set<V>& s2)
{ // Difference

	return Difference(*this, s2);

}
BOOL CFileCompare::Compare(const char* szName1, const char* szName2, CChars* psz1, CChars* psz2, void* pvMem1, void* pvMem2, filePos iLength1, filePos iLength2)
{
	int				i;
	unsigned char*	pcMem1;
	unsigned char*	pcMem2;
	int				iCount;

	if (iLength1 != iLength2)
	{
		psz1->Append(szName1);
		psz1->Append(" size [");
		psz1->Append(iLength1);
		psz1->Append("]");

		psz2->Append(szName2);
		psz2->Append(" size [");
		psz2->Append(iLength2);
		psz2->Append("]");

		return FALSE;
	}

	//Can't compare files that don't exist.
	if ((iLength1 == 0) && (iLength2 == 0))
	{
		return TRUE;
	}

	pcMem1 = (unsigned char*)pvMem1;
	pcMem2 = (unsigned char*)pvMem2;
	iCount = 0;
	for (i = 0; i < iLength1; i++)
	{
		if (pcMem1[i] != pcMem2[i])
		{
			if (iCount == 0)
			{
				ErrorNames(szName1, "Memory", psz1, psz2);
			}

			if (iCount < 16)
			{
				Difference(psz1, i, pcMem1[i]);
				Difference(psz2, i, pcMem2[i]);
			}

			iCount++;
		}
	}

	if (iCount >= 16)
	{
		psz1->Append(" ... ");
		psz1->Append(iCount - 16);
		psz1->Append(" more differences");

		psz2->Append(" ... ");
		psz2->Append(iCount - 16);
		psz2->Append(" more differences");
	}

	return iCount == 0;
}
示例#29
0
void OpenSMOKE_Kinetics::GetDerivativesC(double T, double cTot, BzzMatrix *dRC, 
									   BzzVector &cRes, BzzVector &R)
{
	ChangeDimensions(NC,NC,dRC);
	BzzVector wR(NC);

	int *jD1 = jDir1.GetHandle();
	int *jD2 = jDir2.GetHandle();
	int *jD3 = jDir3.GetHandle();
	int *jD4 = jDir4.GetHandle();
	int *jD5 = jDir5.GetHandle();
	double *vD5 = valDir5.GetHandle();

	int *jIE1 = jInvEq1.GetHandle();
	int *jIE2 = jInvEq2.GetHandle();
	int *jIE3 = jInvEq3.GetHandle();
	int *jIE4 = jInvEq4.GetHandle();
	int *jIE5 = jInvEq5.GetHandle();
	double *vIE5 = valInvEq5.GetHandle();


	double dc,udc;
	int j,k,kd;

	mc = cRes;
	mR = R;

	mr = reactionRates->r;
	mrDirC = reactionRates->rDirC;
	mrInvC = reactionRates->rInvC;

	// derivata rispetto a ckd
	for(kd = 1;kd <= NC;kd++)
	{
		// if(kd==1) cout << "Jacobian evaluation" << endl;
		// Solo se la concentrazione ?praticamente nulla
		if(mc[kd] <= 1.e-100)
		{
			cRes = mc;
			dc = 1.e-10 + 1.e-12 * cRes[kd];
			udc = 3.e-8 * Max(cRes[kd],1./dc);
			udc = Max(udc,1./dc);
			udc = Max(udc,1.e-19);
			dc = Min(udc,.001 + .001 * cRes[kd]);
			cRes[kd] += dc;
			udc = 1. / dc;

			reactionRates->ComputeFromConcentrations(T, cRes, cTot, &wR);
		
			for(j = 1;j <= mc.Size();j++)
				(*dRC)[j][kd] = (wR[j] - mR[j]) * udc;
			for(k = 1;k <= numDir1[kd];k++)
				jD1++;
			for(k = 1;k <= numDir2[kd];k++)
				jD2++;
			for(k = 1;k <= numDir3[kd];k++)
				jD3++;
			for(k = 1;k <= numDir4[kd];k++)
				jD4++;
			for(k = 1;k <= numDir5[kd];k++)
				{jD5++;vD5++;}

			for(k = 1;k <= numInvEq1[kd];k++)
				jIE1++;
			for(k = 1;k <= numInvEq2[kd];k++)
				jIE2++;
			for(k = 1;k <= numInvEq3[kd];k++)
				jIE3++;
			for(k = 1;k <= numInvEq4[kd];k++)
				jIE4++;
			for(k = 1;k <= numInvEq5[kd];k++)
				{jIE5++;vIE5++;}
			continue;
		}

		cRes = mc;
		dc = (S1 - 1.) * mc[kd];
		if(dc == 0.) BzzError("TODO dc = 0. R derivatives");
		cRes[kd] += dc;
		udc = 1. / dc;

		// 1. CALCOLO DELLE REAZIONI DIRETTE E INVERSE
		reactionRates->rDirC = mrDirC;
		reactionRates->rInvC = mrInvC;		
		for(k = 1;k <= numDir1[kd];k++)
			reactionRates->rDirC[*jD1++] *= S1;
		for(k = 1;k <= numDir2[kd];k++)
			reactionRates->rDirC[*jD2++] *= S2;
		for(k = 1;k <= numDir3[kd];k++)
			reactionRates->rDirC[*jD3++] *= S3;
		for(k = 1;k <= numDir4[kd];k++)
			reactionRates->rDirC[*jD4++] *= SSQ;
		for(k = 1;k <= numDir5[kd];k++)
			reactionRates->rDirC[*jD5++] *= pow(S1,*vD5++);

		for(k = 1;k <= numInvEq1[kd];k++)
			reactionRates->rInvC[*jIE1++] *= S1;
		for(k = 1;k <= numInvEq2[kd];k++)
			reactionRates->rInvC[*jIE2++] *= S2;
		for(k = 1;k <= numInvEq3[kd];k++)
			reactionRates->rInvC[*jIE3++] *= S3;
		for(k = 1;k <= numInvEq4[kd];k++)
			reactionRates->rInvC[*jIE4++] *= SSQ;
		for(k = 1;k <= numInvEq5[kd];k++)
			reactionRates->rInvC[*jIE5++] *= pow(S1,*vIE5++);

		// 2. CONTRIBUTI DALLE REAZIONI CON TERZO CORPO
		thirdBody(cRes, cTot, reactionRates->coeffM);

		// 3. CONTRIBUTI DERIVANTI DALLE REAZIONI DI FALLOFF
		fallOff(T, reactionRates->coeffM, reactionRates->k1, reactionRates->k2,
		       reactionRates->logFcent, reactionRates->coeffFallOff);
  
		// 4. ASEMBLAGGIO DEI DIVERSI CONTRIBUTI
		reactionsWithEquilibrium(reactionRates->rDirC, reactionRates->rInvC, reactionRates->uKeq, reactionRates->r);
		reactionsWithThirdBody(reactionRates->coeffM, reactionRates->r);
		//reactionsWithFallOff(reactionRates->coeffFallOff, reactionRates->r);
		
		for(j = 1;j <= NR;j++)
			reactionRates->r[j] *= reactionRates->coeffFallOff[j];

		// 5. COSTRUZIONE DEI CONTRIBUTI PER LE SINGOLE SPECIE
		compositionReactionRates(reactionRates->r, &wR);


		//---------------------------------------------------------------------------
		// Calcolo dello Jacobiano
		//---------------------------------------------------------------------------
		Difference(&wR,mR);
		Product(udc,&wR);
		dRC->SetColumn(kd,wR);
	}

}
示例#30
0
/*virtual*/ void RampToGray::_Execute (Arguments& input_args, Arguments& output_args) {

	// validate input arguments
	CheckInputArguments (input_args, GetInputSignature());
	CheckOutputArguments (output_args, GetOutputSignature());
	
	ByteImage in(input_args[0]), out(output_args[0]);
	pI_bool do_create_data(pI_TRUE);
	if (out.HasData()) {
		if ((out.GetChannels() == 1) &&
			(out.GetWidth() == in.GetWidth()) &&
			(out.GetHeight() == in.GetHeight()))
			do_create_data = pI_FALSE;
	}
	if (do_create_data == pI_TRUE) {
		if (out.HasData()) {
			_runtime.GetCRuntime()->FreeArgumentData (
			 _runtime.GetCRuntime(),
			 output_args[0].get());
		}
		out.SetWidth (in.GetWidth());
		out.SetHeight (in.GetHeight());
		out.SetChannels (1);
		try {
			out.CreateData();
		} catch (exception::MemoryException) {
			throw exception::ExecutionException ("Failed to create grayscale image.");
		}
	}

	pI_byte r, g, b;
	pI_float rf, gf, bf;
	pI_size index1, index2;
	// Note: currently, this is done in ByteImage::CreateData()
	// out.SetPitch ((((8 * in.GetWidth()) + 31) / 32) * 4);
	out.SetPath (in.GetPath());
	for (pI_size h = 0; h < in.GetHeight(); ++h) {
		for (pI_size w = 0; w < in.GetWidth(); ++w) {
			r = in.GetData (h, w, 0), g = in.GetData (h, w, 1), b = in.GetData (h, w, 2);
			rf = static_cast<pI_float> (r) / 255.0f;
			gf = static_cast<pI_float> (g) / 255.0f;
			bf = static_cast<pI_float> (b) / 255.0f;
			// in case of gray value, keep it
			if ((r == g) && (r == b)) {
				out.SetData (h, w, 0, r);
				continue;
			}
			GetBestCandidates (rf, gf, bf, index1, index2);
			// check if best candidates are neighbours
			if (std::abs (static_cast<int> (index1) - static_cast<int> (index2)) > 1) {
				// if not, use best candidate
				out.SetData (h, w, 0, static_cast<pI_byte> ((static_cast<float> (index1) / static_cast<float> (_colour_map.size())) * 255.0f));
			} else {
				// otherwise, interpolate
				t_cc cc1(_colour_map[index1 < index2 ? index1 : index2]);
				t_cc cc2(_colour_map[index1 > index2 ? index1 : index2]);
				t_cc diff_cc(Difference (cc1.r, cc2.r), Difference (cc1.g, cc2.g), Difference (cc1.b, cc2.b));
				t_cc diff_p_cc2(Difference (cc2.r, rf), Difference (cc2.g, gf), Difference (cc2.b, bf));
				pI_float norm_diff(0.0f);
				if (diff_cc.r > 0.0)
					norm_diff += diff_p_cc2.r / diff_cc.r;
				if (diff_cc.g > 0.0)
					norm_diff += diff_p_cc2.g / diff_cc.g;
				if (diff_cc.b > 0.0)
					norm_diff += diff_p_cc2.b / diff_cc.b;
				norm_diff /= 3.0f;
				out.SetData (h, w, 0, static_cast<pI_byte> (((static_cast<float> (index1) + norm_diff) / static_cast<float> (_colour_map.size())) * 255.0f));
			}
			
		}
	}
}