Example #1
0
Image GA::cross(const Image& mother, const Image& father, std::vector<Triangle>& used)
{
    Image child(mother.surface->w, mother.surface->h);
    child.triangles.reserve(trianglesCount);

    // get random line trought the image
    Vector2 p1 = rnd.getRandomCoordinate(mother.surface->w, mother.surface->h);
    Vector2 p2 = rnd.getRandomCoordinate(mother.surface->w, mother.surface->h);

    p2 = p1 == p2 ? Vector2(p1.y, p1.x) : p2;

    int count = 0; // count of triangles added int child

    for (auto & tr : father.triangles)
    {
        if (count >= trianglesCount) break;
        if (isOnRightTriangle(tr, p1, p2))
        {
            child.triangles.push_back(tr);
            used.push_back(tr);
            count++;
        }
    }

    for (auto & tr : mother.triangles)
    {
        if (count >= trianglesCount) break;
        if (!isOnRightTriangle(tr, p1, p2))
        {
            child.triangles.push_back(tr);
            used.push_back(tr);
            count++;
        }
    }

    if (count < trianglesCount)
    {
        for (int c = 0; c < trianglesCount; ++c)
        {
            if (count < trianglesCount) {
                if (isNotUsed(used, father.triangles[c]))
                {
                    child.triangles.push_back(father.triangles[c]);
                    count++;
                }
            }
        }
    }

    if (child.triangles.size() != trianglesCount) __debugbreak();

    //draw image pixels
    child.generatePixels();

    return child;
}
Example #2
0
OsStatus MpOss::freeInputDevice()
{
   OsStatus ret = OS_SUCCESS;
   if (mStReader)
   {
      //It's very bad freeing device when it is enabled
      ret = detachReader();
   }

   if (mReader != NULL)
      mReader = NULL;
   else
      ret = OS_FAILED;

   if (isNotUsed())
   {
      noMoreNeeded();
   }
   return ret;
}
Example #3
0
OsStatus MpOss::freeOutputDevice()
{
   OsStatus ret = OS_SUCCESS;
   if (mStWriter)
   {
      //It's very bad freeing device when it is enabled
      ret = detachWriter();
   }

   if (mWriter != NULL)
   {
      mWriter = NULL;
   }
   else
   {
      ret = OS_FAILED;
   }

   if (isNotUsed())
   {
      noMoreNeeded();
   }
   return ret;
}