I have created an icosahedron and subdivided it, I am not trying to display it but it seems to be displaying it un-subdivided. Here is my code:
vtkSmartPointer<vtkPlatonicSolidSource> icosahedron = vtkSmartPointer<vtkPlatonicSolidSource>::New();
icosahedron->SetSolidTypeToIcosahedron();
icosahedron->Update();
cout << " Centre is " << icosahedron->GetOutput()->GetCenter()[0] << ", " << icosahedron->GetOutput()->GetCenter()[1] << ", " << icosahedron->GetOutput()->GetCenter()[2] << endl;
cout << " There are " << icosahedron->GetOutput()->GetNumberOfPolys() << " triangles." << endl;
cout << " there are " << icosahedron->GetOutput()->GetNumberOfPoints() << " points " << endl;
vtkSmartPointer<vtkPolyDataAlgorithm> subdivisionFilter;
subdivisionFilter = vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
dynamic_cast<vtkLinearSubdivisionFilter *> (subdivisionFilter.GetPointer())->SetNumberOfSubdivisions(2);
subdivisionFilter->SetInput(icosahedron->GetOutput());
subdivisionFilter->Update();
cout << " After " << endl;
std::cout << " There are " << subdivisionFilter->GetOutput()->GetNumberOfPoints() << " points." << std::endl;
std::cout << " There are " << subdivisionFilter->GetOutput()->GetNumberOfPolys() << " triangles." << std::endl;
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(subdivisionFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
//Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(.1, .2, .3);
//Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
The console output is:
Centre is 0, 0, 0
There are 20 triangles.
there are 12 points
After
There are 162 points.
There are 320 triangles.
Confirming that it has indeed been subdivided.
I can see the divisions after turning on wireframe mode:
#include <vtkProperty.h>
....
actor->GetProperty()->SetRepresentationToWireframe();
What you are seeing is that the algorithm is adding the new points in the same plane as the existing triangle, so when you render the result as a surface it does not look any different.
Related
I have a group of numbers like this:
11341
11341
11342
11342
11343
11344
11344
...
50001
50001
50002
...
I want to be able to generate a color based on each unique number so that numbers close together have contrasting colors.
The concept: Each of these numbers corresponds to a session id, I want each session to be color coded, but sessions that are close together should not have similar colors.
I've tried the concept written about here and it works, except close numbers tend to have similar colors.
Thoughts?
I like Antoine Lefebvre's answer, however you still have the issue of two non-contrasting colors being near each other (say because of a long lasting session that out lives all it's neighbor sessions).
--This is not something I considered when I wrote this question, but I'm finding is a real issue that needs considering.
The solution I ended up going with is to create a maximum contrasting color palette, then using the session_id to access that palette.
I took a look at this palette:
Kelly's 22 Colours of Maximum contrast [Editor's note: URL changed.]
I liked it a lot because it takes color blindness into account. But the limit of 22 colors was not enough for me.
So I ended up using this palette: A color dictionary of 269 maximally distinct colors from all previous colors
Here is my solution (Written using CPP and QT):
QColor colorForIndex(int index)
{
static QStringList colorList = QStringList()
<< "#000000" << "#FFFF00" << "#1CE6FF" << "#FF34FF" << "#FF4A46" << "#008941" << "#006FA6" << "#A30059" << "#FFDBE5" << "#7A4900"
<< "#0000A6" << "#63FFAC" << "#B79762" << "#004D43" << "#8FB0FF" << "#997D87" << "#5A0007" << "#809693" << "#FEFFE6" << "#1B4400"
<< "#4FC601" << "#3B5DFF" << "#4A3B53" << "#FF2F80" << "#61615A" << "#BA0900" << "#6B7900" << "#00C2A0" << "#FFAA92" << "#FF90C9"
<< "#B903AA" << "#D16100" << "#DDEFFF" << "#000035" << "#7B4F4B" << "#A1C299" << "#300018" << "#0AA6D8" << "#013349" << "#00846F"
<< "#372101" << "#FFB500" << "#C2FFED" << "#A079BF" << "#CC0744" << "#C0B9B2" << "#C2FF99" << "#001E09" << "#00489C" << "#6F0062"
<< "#0CBD66" << "#EEC3FF" << "#456D75" << "#B77B68" << "#7A87A1" << "#788D66" << "#885578" << "#FAD09F" << "#FF8A9A" << "#D157A0"
<< "#BEC459" << "#456648" << "#0086ED" << "#886F4C" << "#34362D" << "#B4A8BD" << "#00A6AA" << "#452C2C" << "#636375" << "#A3C8C9"
<< "#FF913F" << "#938A81" << "#575329" << "#00FECF" << "#B05B6F" << "#8CD0FF" << "#3B9700" << "#04F757" << "#C8A1A1" << "#1E6E00"
<< "#7900D7" << "#A77500" << "#6367A9" << "#A05837" << "#6B002C" << "#772600" << "#D790FF" << "#9B9700" << "#549E79" << "#FFF69F"
<< "#201625" << "#72418F" << "#BC23FF" << "#99ADC0" << "#3A2465" << "#922329" << "#5B4534" << "#FDE8DC" << "#404E55" << "#0089A3"
<< "#CB7E98" << "#A4E804" << "#324E72" << "#6A3A4C" << "#83AB58" << "#001C1E" << "#D1F7CE" << "#004B28" << "#C8D0F6" << "#A3A489"
<< "#806C66" << "#222800" << "#BF5650" << "#E83000" << "#66796D" << "#DA007C" << "#FF1A59" << "#8ADBB4" << "#1E0200" << "#5B4E51"
<< "#C895C5" << "#320033" << "#FF6832" << "#66E1D3" << "#CFCDAC" << "#D0AC94" << "#7ED379" << "#012C58" << "#7A7BFF" << "#D68E01"
<< "#353339" << "#78AFA1" << "#FEB2C6" << "#75797C" << "#837393" << "#943A4D" << "#B5F4FF" << "#D2DCD5" << "#9556BD" << "#6A714A"
<< "#001325" << "#02525F" << "#0AA3F7" << "#E98176" << "#DBD5DD" << "#5EBCD1" << "#3D4F44" << "#7E6405" << "#02684E" << "#962B75"
<< "#8D8546" << "#9695C5" << "#E773CE" << "#D86A78" << "#3E89BE" << "#CA834E" << "#518A87" << "#5B113C" << "#55813B" << "#E704C4"
<< "#00005F" << "#A97399" << "#4B8160" << "#59738A" << "#FF5DA7" << "#F7C9BF" << "#643127" << "#513A01" << "#6B94AA" << "#51A058"
<< "#A45B02" << "#1D1702" << "#E20027" << "#E7AB63" << "#4C6001" << "#9C6966" << "#64547B" << "#97979E" << "#006A66" << "#391406"
<< "#F4D749" << "#0045D2" << "#006C31" << "#DDB6D0" << "#7C6571" << "#9FB2A4" << "#00D891" << "#15A08A" << "#BC65E9" << "#FFFFFE"
<< "#C6DC99" << "#203B3C" << "#671190" << "#6B3A64" << "#F5E1FF" << "#FFA0F2" << "#CCAA35" << "#374527" << "#8BB400" << "#797868"
<< "#C6005A" << "#3B000A" << "#C86240" << "#29607C" << "#402334" << "#7D5A44" << "#CCB87C" << "#B88183" << "#AA5199" << "#B5D6C3"
<< "#A38469" << "#9F94F0" << "#A74571" << "#B894A6" << "#71BB8C" << "#00B433" << "#789EC9" << "#6D80BA" << "#953F00" << "#5EFF03"
<< "#E4FFFC" << "#1BE177" << "#BCB1E5" << "#76912F" << "#003109" << "#0060CD" << "#D20096" << "#895563" << "#29201D" << "#5B3213"
<< "#A76F42" << "#89412E" << "#1A3A2A" << "#494B5A" << "#A88C85" << "#F4ABAA" << "#A3F3AB" << "#00C6C8" << "#EA8B66" << "#958A9F"
<< "#BDC9D2" << "#9FA064" << "#BE4700" << "#658188" << "#83A485" << "#453C23" << "#47675D" << "#3A3F00" << "#061203" << "#DFFB71"
<< "#868E7E" << "#98D058" << "#6C8F7D" << "#D7BFC2" << "#3C3E6E" << "#D83D66" << "#2F5D9B" << "#6C5E46" << "#D25B88" << "#5B656C"
<< "#00B57F" << "#545C46" << "#866097" << "#365D25" << "#252F99" << "#00CCFF" << "#674E60" << "#FC009C" << "#92896B";
int colorIndex = index % colorList.size();
return QColor(colorList.value(colorIndex, "white"));
}
You could compute a RGB color code based on the session id.
To have contrasting colors, just calculate session id mod 3 and based on that value (0, 1 or 2) change the logic to assign the R,G,B values
Example:
switch(session_id mod 3){
case 0: R = session_id mod 256; G = (session_id / 256) mod 256;B = (session_id / 65536) mod 256;
case 1: G = session_id mod 256; B = (session_id / 256) mod 256;R = (session_id / 65536) mod 256;
case 2: B = session_id mod 256; R = (session_id / 256) mod 256;G = (session_id / 65536) mod 256;
of course you can adapt the formula to calculate the RGB values.
I was trying to make use of the new Shape Transformers and Interfaces of OpenCV3.0. Unfortunately it doesn't work as expected. To ensure not making any fancy warps and getting strange results cause of that reason I initialized a transformation where nothing at all should happen. But output of the transformation for a testpoint is always [0,0] and the warped image is always completley gray. Any suggestions what could be wrong are welcome.
int main(void){
Mat img1 = imread("C:\\opencv\\sources\\samples\\data\\graf1.png", IMREAD_GRAYSCALE);
std::vector<cv::Point2f> points1, testpoints;
vector<DMatch> good_matches;
Mat respic, resmat;
points1.push_back(Point(0, 0)); //Corners 800x600 pic
points1.push_back(Point(799, 0));
points1.push_back(Point(799, 599));
points1.push_back(Point(0, 599));
Mat pointmatrix1(points1);
good_matches.push_back(DMatch(0, 0, 0));
good_matches.push_back(DMatch(1, 1, 0));
good_matches.push_back(DMatch(2, 2, 0));
good_matches.push_back(DMatch(3, 3, 0));
testpoints.push_back(Point(250, 250));
Mat testpointsmat(testpoints);
// Apply TPS
Ptr<ThinPlateSplineShapeTransformer> mytps = createThinPlateSplineShapeTransformer(0);
mytps->estimateTransformation(pointmatrix1, pointmatrix1, good_matches); // Using same pointmatrix nothing should change in res
mytps->applyTransformation(testpointsmat, resmat);
cout << "pointmatrix1 = " << endl << " " << pointmatrix1 << endl << endl;
cout << "testpointsmat = " << endl << " " << testpointsmat << endl << endl;
cout << "resmat = " << endl << " " << resmat << endl << endl; //Always [0,0] ?
imshow("img1", img1); // Just to see if I have a good picture
mytps->warpImage(img1, respic);
imwrite("Tranformed.png", respic);
imshow("Tranformed", respic); //Always completley grey ?
waitKey(0);
return 0;
}
Don't ask me why but if I add this two lines it works.
// Apply TPS
transpose(pointmatrix1, pointmatrix1); // ADD
transpose(testpoints, testpoints); // ADD
Ptr<ThinPlateSplineShapeTransformer> mytps = createThinPlateSplineShapeTransformer(0);
Now There is something strange in source code here why cols and not rows.
by LBerger
I am trying to work out the angle of a right angled triangle. I have an array containing the lengths of the two sides of the triangle. I also have an array containing the Euclidean Distance between these two points. How would I find the angle of the triangles? In other words, how would I do the sin and then arcsin methods to find the angle? I am just looking for the angle opposite of the hypotenuse. I'm trying to do this in C++.
Solved it now, misinterpreted what I had been asked to do
Solution: How would I find the angle of the triangles
#include <iostream>
#include <cmath>
using namespace std;
#define radians(x) return x * (180/pi)
int main()
{
double opposite, adjacent, angle1, angle2, angle3, choice, radians, hypotenuse;
cout << "Opposite: ";
cin >> opposite;
cout << "Adjacent: ";
cin >> adjacent;
cout << "Radians or Degrees: (R/D)";
cin >> choice;
if(choice == "R")
{
angle1 = arctan(adjacent/opposite);
hypotenuse = opposite\cos(radians(angle1));
angle2 = arcsin(adjacent\hypotenuse);
cout << "Angle 1: "<< radians(angle1) << endl;
cout << "Angle 2: "<< "90\n";
cout << "Angle 3: "<< radians(angle2) << endl;
cout << "Hypotenuse: " << hypotenuse;
}
else if(choice = "D")
{
angle1 = arctan(adjacent/opposite);
hypotenuse = opposite\cos((angle1));
angle2 = arcsin(adjacent\hypotenuse);
cout << "Angle 1: " << (angle1) << endl;
cout << "Angle 2: " << "90\n";
cout << "Angle 3: " << (angle2) << endl;
cout << "Hypotenuse: " << hypotenuse;
}
return 0;
}
or just
angle2 = 180 - (angle1 + 90)
The relation between sides and angles of triangle is:-
a/sinA = b/sinB = c/sinC
where 'a' is the side opposite angle 'A'.
You know one angle let's say it's A = 90. Then you can calculate other two angles from above equation.
You have the lengths of the sides, if you us tangents, you can find the angle for the corresponding side.
Also, once you find one angle, all you need to do is subtract 90 from it to get the final angle:
tan(angle) = opposite/adjacent;
angle = arctan(opposite/adjacent);
otherAngle = 90 - angle;
Okay I'm not exactly sure where I'm going wrong here, but any kind of help would be vastly appreciated. I When i input the values for the pay rate and the hours worked each week (which is wk1-wk5), i am getting a zero for all my calculations.
Here is source Code:
#include <iostream>
using namespace std;
const double tax = 0.14;
int main()
{
int wk1,wk2,wk3,wk4,wk5;
wk1 = wk2 = wk3 = wk4 = wk5 = 0;
double payrate;
payrate = 0;
cout << "Please enter the payrate for employee." << endl;
cin >> payrate;
cout << "Please enter employee's total hours for week one:" << endl;
cin >> wk1;
cout << "Please enter employee's total hours for week two:" << endl;
cin >> wk2;
cout << "Please enter employee's total hours for week three:" << endl;
cin >> wk3;
cout << "Please enter employee's total hours for week four:" << endl;
cin >> wk4;
cout << "Please enter employee's total hours for week five:" << endl;
cin >> wk5;
int thours = wk1 + wk2 + wk3 + wk4 + wk5;
thours = 0;
double gross = payrate * thours;
double taxes = tax * gross;
double net = gross - taxes;
double clothes = 0.10 * net;
double supplies = 0.10 * net;
double remaining = net - clothes - supplies;
double bonds = 0.25 * remaining;
double pbonds = 0.50 * bonds;
cout << "Here is income before taxes: " << gross << endl;
cout << "Here is income after taxes: " << net << endl;
cout << "Here is clothes and accesories: " << clothes << endl;
cout << "Here is School supplies: " << supplies << endl;
cout << "Here is personal bonds: " << bonds << endl;
cout << "Here is parents bonds: " << pbonds << endl;
return 0;
}
You incorrectly assume that by assigning an expression such as double x= y*3 to a variable, that its value will always be determined by the value of y throughout your program. That's not the case.
What this does is that the value in y is copied, multiplied by 3 and then assigned to x. So if at the time of assignment, y was 10, it will always be 10 no matter how y changes in the future unless you reassign x with the new value of y.
So in order to solve your problem, perform the calculations after you receive the values of your variables.
+
Also, this line:
int thours = wk1 + wk2 + wk3 + wk4 + wk5;
thours = 0;
After you assign the wk variables to thours, you set it back to zero. What you should be doing:
int thours = 0;
thours = wk1 + wk2 + wk3 + wk4 + wk5;
I can't seem to get it to count down on the last verse. I've tried to create a new variable that subtracts 1 and put that variable in the last verse and it works for all but numbers 9, 19, 29, 39...99. Can someone please give me a hint or point me in the right direction? I've also tried creating another loop to count down and read it from the array. I have only been learning this for a few months and don't know what else to try. I thought I once I got to this point the hard part was behind me, not so much, for me at least. Thank you. It is c++ in Visual studio 2010.
#include <iostream>
#include <string>
using namespace std;
string tens[11] = {""," Ten"," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety"};
string ones[10] = {"","-One","-Two","-Three","-Four","-Five","-Six","-Seven","-Eight","-Nine"};
string s_ones[11] = {" Zero"," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine"};
string other[ ] = {" Ten"," Eleven"," Twelve"," Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen",""};
int main()
{
for(int i = 99; i >= 0; --i)
{
int tens_place = i / 10, ones_place = i % 10, small_ones_place = i % 10;
if(10 <= i && i < 20)
{
cout << other[i - 10] << " bottles of beer on the wall. \n"
<< other[i - 10] << " bottles of beer.\n"
<< " Take one down, pass it around,\n"
<< other[(i - 10)] << " bottles of beer on the wall.\n\n";
}
if(20 <= i && i <= 99)
cout << tens[tens_place] + ones[ones_place] << " bottles of beer on the wall. \n"
<< tens[tens_place] + ones[ones_place] << " bottles of beer.\n"
<< " Take one down, pass it around,\n"
<< tens[tens_place] + ones[ones_place] << " bottles of beer on the wall.\n\n";
if(2 <= i && i < 10)
cout << s_ones[small_ones_place] << " bottles of beer on the wall.\n"
<< s_ones[small_ones_place] << " bottles of beer.\n"
<< " Take one down, pass it around,\n"
<< s_ones[small_ones_place] << " bottles of beer on the wall.\n\n";
if(i == 1)
cout << s_ones[small_ones_place] << " bottle of beer on the wall.\n"
<< s_ones[small_ones_place] << " bottle of beer.\n"
<< " Take one down, pass it around,\n"
<< s_ones[small_ones_place] << " bottles of beer on the wall.\n\n";
if(i == 0)
cout << s_ones[small_ones_place] << " bottles of beer on the wall.\n"
<< s_ones[small_ones_place] << " bottles of beer.\n"
<< " Go to the store and get some more,\n"
<< " Ninety-nine bottles of beer on the wall.\n\n";
}
return(0);
}
It comes very close to working correctly. All you have to do is subtract 1 from the one's place index on the last line. Like this:
<< " Take one down, pass it around,\n"
<< other[(i - 10)-1] << " bottles of beer on the wall.\n\n";