|
Hi,
I have several (6)points(x,y) and having troubles smoothing the curves of these points. I tried using the PolyBezier function without any luck. I would like to provide the points, and the function to draw the smoothed curves that is very similar to what Excel does. Any ideas?
Thanks
|
|
|
|
|
Ok... I think you are going down the right path with PolyBezier. But you have to think a bit about how beziers work. There's an article here[^] on the subject (ignore the code at the bottom - windows implements that for you!). So each point on the polygon has two bezier handles associated with it... one for the next line segment, and on for the previous. Now what I think Excel does is choose the positions of those bezier handles for you automatically. The two points are in a smooth arrangement - so the the polygon point, and the two bezier handles form a straight line. The distance between the handle and polygon point is chosen in proportion to the length of the line segmet it applies to. With me so far?
Additionally the line formed by the polygon point and the two bezier handles is angled in way to be sort of tangential to the polygons. It seems to take an average between the angle of the first and last segments (whether weigthed by length I'm not sure).
so I think you need to do something like this:
void DrawSmoothedPolygon(HDC dc, POINT *pointlist, int pointcount)
{
const float curvyness = 0.1f;
float prevseglength, nextseglength;
long dx, dy;
long leapfrogdx, leapfrogdy;
ASSERT(pointlist != NULL);
ASSERT(pointcount >= 3);
POINT *curvepoints = new POINT[pointcount * 3 + 1];
curvepoints[0] = pointlist[i];
curvepoints[1] = pointlist[i];
curvepoints[pointcount * 3 + 1] = pointlist[pointcount];
curvepoints[pointcount * 3] = pointlist[pointcount];
dx = (curvepoints[1].x - curvepoints[0].x);
dy = (curvepoints[1].y - curvepoints[0].y);
nextseglength = sqrt(dx*dx + dy*dy);
for(int i = 1; i < pointcount - 1; i++)
{
leapfrogdx = (curvepoints[i-1].x - curvepoints[i+1].x);
leapfrogdy = (curvepoints[i-1].y - curvepoints[i+1].y);
preveglength = nextseglength;
dx = (curvepoints[i+1].x - curvepoints[i].x);
dy = (curvepoints[i+1].y - curvepoints[i].y);
nextseglength = sqrt(pointlist[i].x * pointlist[i].x + pointlist[i].y * pointlist[i].y);
curvepoints[i * 3] = pointlist[i];
curvepoints[i * 3 + 1].x = pointlist[i].x + leapfrogdx / (nextseglength / curvyness);
curvepoints[i * 3 + 1].y = pointlist[i].y + leapfrogdy / (nextseglength / curvyness);
curvepoints[i * 3 - 1].x = pointlist[i].x - leapfrogdx / (prevseglength / curvyness);
curvepoints[i * 3 - 1].y = pointlist[i].y - leapfrogdy / (prevseglength / curvyness);
}
PolyBezier(dc, curvepoints, pointcount * 3 + 1);
delete[] curvepoints;
} Now I'm not sure how well this will work. But it may give you some ideas to start with. Also it doesn't deal with closed curves... I'll leave you to figure those out
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^] - now available in MSWord format![^]
|
|
|
|
|
I have a class exported from a DLL which has a member of type _ConnectionPtr. I am importing the ADO library in the DLL as follows:
#import "msado15.dll" no_namespace named_guids rename("EOF", "adoEOF")
The _ConnectionPtr is defined using the _com_ptr_t<..> template in the ADO library, and since the template definition is not exported I get the above warning when compiling.
If I had a member of a simpler template type in the class, for e.g.:
MyTemplate<int> my_member;
..it would just be a matter of exporting the 'instantiated' template definition in the class definition like this:
<br />
class __declspec(dllexport) CParameters<br />
{<br />
public: ....<br />
protected: ....<br />
<br />
template class __declspec(dllexport) MyTemplate<int>;<br />
MyTemplate<int> my_param;<br />
};<br />
However, i am at a loss on how to proceed with the _ConnectionPtr template definition. The warning i get from the compiler is as follows (m_pConn is the member, CParameters is the exported class):
warning C4251: 'm_pConn' : class '_com_ptr_t<class _com_IIID<struct _Connection,&struct __s_GUID _GUID_00000550_0000_0010_8000_00aa006d2ea4> >' needs to have dll-interface to be used b<br />
y clients of class 'CParameters'
Otherwise, the thing compiles ok and the m_pConn is initialised properly as a connection, but i would like to iron out these warnings.
Any ideas?
|
|
|
|
|
It's not very useful to export classes with templates!
You can fix the problem by creating a static library instead of a DLL.
The compiler tells you that an application that wants to use the DLL has to know the definition of _com_ptr_t<class _com_iiid<struct="" _connection,&struct="" __s_guid="" _guid_00000550_0000_0010_8000_00aa006d2ea4=""> > to be able to use the class. A static library would be the best solution.
Don't try it, just do it!
|
|
|
|
|
Hi Alex...thanks for replying.
The thing is this: the dll i am writing will be used by a service. If i link it statically, i would have to re-compile the service each time i change something in the dll, right? It's something i would like to avoid.
The problem lies in the ADO template which i am using in my dll. If it was my template i would have found another way, however i'm not that flexible with ADO.
Further feedback is welcome...!
|
|
|
|
|
|
Yes...saw that...but can't find how to use the same approach for the _ConnectionPtr for ADO...the declaration is way too complex.
|
|
|
|
|
What about using the pragma warning??
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Yes ok, it will work...but it's not much of a solution now, is it?
|
|
|
|
|
My program needs to access shares on a different computer but as a different user than the one running the application. If anybody can point me to the basic API functions to do this, it will be greatly appreciated.
The basic function I guess would be to stablish a connection with credentials programatically. In any case I just need a pointer to the documentation.
Thank you
|
|
|
|
|
Something like this:
LogonUserEx() -> ImpersonateLoggedOnUser() -> Access The Shares -> RevertToSelf()
|
|
|
|
|
You can use NetUseAdd() for this.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thank you! NetUseAdd() is exactly what I was looking for
The one for the local computer is interesting too, good to know it's also possible.
Thank you both.
|
|
|
|
|
hi
I have problem in sorting the array alphbetically.
I have the names of students only first names.I have the function which works but doesn't gives the consistent result as it should .
So can any one help in getting the problem to be solved
my array declaration is char *names[100];
Best REgards
Jhon
|
|
|
|
|
If you post what you've come up with so far, I'm sure someone here will be able to solve the problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
can you use STL? if so, there's functions for that, I think... Or is this a class project in which you have to write your own sorting? If so, look up "Quick sort" or "bubble sort"
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
what does multi-monitors mean?? Is the same thing shown on both monitors? Do you need 2 or more mouses for each monitor?
|
|
|
|
|
You have one video card driving two monitors (video display hardware), or two video cards driving one or more monitors each. You can sometimes have different desktops on each monitor or one desktop spread across multiple monitors. One mouse typically for the entire system. The mouse typically seamlessly travels from one 'screen' to the next. I like having two monitors because I can run my program on one and run the Visual Studio on the other to debug the program running on the first monitor. Or I can run ZoomIn on the second monitor to spy on the graphics of the first monitor - in this case, it is almost like having the same thing on both monitors, except one of them is magnified. They do not necessarily display the same things, though.
|
|
|
|
|
Hi everybody!!
I have to synchronize a thread with the process. I have to do this :
each 2 seconds and every time OnDraw() is called (event)
For that I have to include "WaitForMultipleObjects" into the thread to wait for this 2 events.
My problem is how can to synchronize the thread...I have had a look to "WaitForMultipleObjects" in MSDN and it says something of using a handler. How can I do it? Could you attach a simple exemple, please?
Thanks you very much.
|
|
|
|
|
Sry, I don't understand your issue.
Don't try it, just do it!
|
|
|
|
|
You need a single 'Event' object. See CreateEvent.
Whne the OnDraw is called or 2 seconds have passed, call SetEvent.
Write your thread to wait on the event handle returned from CreateEvent.
So, then, your thread will 'run' when the event is signalled.
|
|
|
|
|
This is my first experience with maps and I am having some troubles.
I have developed a Logger that can do private logs depending on the client who calls the COM object. Based on the client's information, it needs to find the specific file to log to.
Here is my code:
//(header declarations)
std::map<BSTR, ofstream*> m_FileList;
std::map<BSTR, ofstream*>::iterator mFileListIterator;
//(code)
bool ClientHasCalledBefore;
_bstr_t FileName; //name of the file coming in.
//Look for FileName in map to see if it was called before.
ClientHasCalledBefore = (!(m_FileList.find(FileName) == m_FileList.end()));
// If it has called before, it logs to a clear file.
// If not, it creates the file, then appends the logs.
if (!ClientHasCalledBefore)
{
ofstream *ofstr = new ofstream(FileName, ios::out);
m_FileList[FileName] = ofstr;
*m_FileList[FileName] << "EntryToBeLogged";
m_FileList[FileName]->close();
}
else
{
m_FileList[FileName]->open(FileName, ios::app);
*m_FileList[FileName] << "EntryToBeLogged";
m_FileList[FileName]->close();
}
Okay. This code leads me to my first question. When I enter a new file into the map, sometimes it does not enter properly and the next time the conditional is checked, the FileName is not found. It does this sometimes the first one to three times it runs through. After the first couple of times, everything works fine. Because I am opening the file clean, this overwrites the first couple of entries. Any suggestions so that my conditional finds the entry in the map the first time?
//**************
In my destructor, I have this code to add a footer to every file:
for (m_FileListIterator = m_FileList.begin(); m_FileListIterator != m_FileList.end(); ++m_FileListIterator)
{
(m_FileListIterator->second)->open(FileListIterator->first, ios::app);
*(m_FileListIterator->second) << "FooterToBeAdded";
(m_FileListIterator->second)->close();
}
I think something is totally flawed with this. Sometimes it will append to a file I would have never created in my code, making a new file. Other times it will log the footer into the same file multiple times. It is almost as if it is not iterating.
Again, this is my first experience with any of this. Any help is much appreciated. Thank you.
|
|
|
|
|
Hello ChemmieBro, next time you post here please make sure you check on the "Do not treat <'s as HTML tags" checkbox below the input window: otherwise your < 's and > 's won't show up properly. For the benefit of other readers, I'm reproducing here the definition of m_FileList with the bracket thing right:
std::map<BSTR, ofstream*> m_FileList; The problem you're having is most likely the following: when you look up an item in std::map , the key you pass is compared against those of the elements stored in the map. So far so good, but in your case it is BSTR s that are used as keys, and these are pointers: so, instead of comparing the contents pointed to by the BSTR , it is the pointer addresses that std::map is taking into account, certainly not what you want. The most straightforward solution is to use as keys another type of objects with the right comparison semantics, like for instance MFC CString or some other wrapper around raw BSTR s.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thanks for your help. I'm brand new to using BSTRs also.
I do not have access to MFC here, so the CString is out. I will look into using some kind of wrapper around the BSTRs.
|
|
|
|
|
Check Michael Dunn and Nishant Sivakumar's Complete Guide to C++ Strings, Part II [^], you might find what you need there.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|